Move positioning logic out of x_win_move
This commit is contained in:
		
							parent
							
								
									4faa9cbaaa
								
							
						
					
					
						commit
						f513d8417f
					
				
							
								
								
									
										29
									
								
								src/draw.c
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								src/draw.c
									
									
									
									
									
								
							| @ -479,6 +479,31 @@ static struct dimensions layout_render(cairo_t *c, colored_layout *cl, colored_l | |||||||
|         return dim; |         return dim; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /**
 | ||||||
|  |  * Calculates the position the window should be placed at given its width and | ||||||
|  |  * height and stores them in \p ret_x and \p ret_y. | ||||||
|  |  */ | ||||||
|  | static void calc_window_pos(int width, int height, int *ret_x, int *ret_y) | ||||||
|  | { | ||||||
|  |         screen_info *scr = get_active_screen(); | ||||||
|  | 
 | ||||||
|  |         if (ret_x) { | ||||||
|  |                 if (settings.geometry.negative_x) { | ||||||
|  |                         *ret_x = (scr->x + (scr->w - width)) + settings.geometry.x; | ||||||
|  |                 } else { | ||||||
|  |                         *ret_x = scr->x + settings.geometry.x; | ||||||
|  |                 } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (ret_y) { | ||||||
|  |                 if (settings.geometry.negative_y) { | ||||||
|  |                         *ret_y = scr->y + (scr->h + settings.geometry.y) - height; | ||||||
|  |                 } else { | ||||||
|  |                         *ret_y = scr->y + settings.geometry.y; | ||||||
|  |                 } | ||||||
|  |         } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void draw(void) | void draw(void) | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| @ -487,12 +512,14 @@ void draw(void) | |||||||
|         struct dimensions dim = calculate_dimensions(layouts); |         struct dimensions dim = calculate_dimensions(layouts); | ||||||
|         int width = dim.w; |         int width = dim.w; | ||||||
|         int height = dim.h; |         int height = dim.h; | ||||||
|  |         int win_x, win_y; | ||||||
| 
 | 
 | ||||||
|         cairo_t *c; |         cairo_t *c; | ||||||
|         cairo_surface_t *image_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); |         cairo_surface_t *image_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); | ||||||
|         c = cairo_create(image_surface); |         c = cairo_create(image_surface); | ||||||
| 
 | 
 | ||||||
|         x_win_move(width, height); |         calc_window_pos(dim.w, dim.h, &win_x, &win_y); | ||||||
|  |         x_win_move(win_x, win_y, width, height); | ||||||
|         cairo_xlib_surface_set_size(root_surface, width, height); |         cairo_xlib_surface_set_size(root_surface, width, height); | ||||||
| 
 | 
 | ||||||
|         cairo_move_to(c, 0, 0); |         cairo_move_to(c, 0, 0); | ||||||
|  | |||||||
							
								
								
									
										40
									
								
								src/x11/x.c
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								src/x11/x.c
									
									
									
									
									
								
							| @ -51,41 +51,26 @@ cairo_surface_t *x_create_cairo_surface(void) | |||||||
|                         xctx.win.xwin, DefaultVisual(xctx.dpy, 0), WIDTH, HEIGHT); |                         xctx.win.xwin, DefaultVisual(xctx.dpy, 0), WIDTH, HEIGHT); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void x_win_move(int width, int height) | void x_win_move(int x, int y, int width, int height) | ||||||
| { | { | ||||||
|         // Previous dimensions of the window to avoid calling X11 if no change
 |         // Previous dimensions of the window to avoid calling X11 if no change
 | ||||||
|         // is needed
 |         // is needed
 | ||||||
|         static struct dimensions window_dim = { 0 }; |         static struct dimensions window_dim = { 0 }; | ||||||
| 
 | 
 | ||||||
|         int x, y; |  | ||||||
|         screen_info *scr = get_active_screen(); |  | ||||||
|         xctx.win.cur_screen = scr->id; |  | ||||||
| 
 |  | ||||||
|         /* calculate window position */ |  | ||||||
|         if (settings.geometry.negative_x) { |  | ||||||
|                 x = (scr->x + (scr->w - width)) + settings.geometry.x; |  | ||||||
|         } else { |  | ||||||
|                 x = scr->x + settings.geometry.x; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (settings.geometry.negative_y) { |  | ||||||
|                 y = scr->y + (scr->h + settings.geometry.y) - height; |  | ||||||
|         } else { |  | ||||||
|                 y = scr->y + settings.geometry.y; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         /* move and resize */ |         /* move and resize */ | ||||||
|         if (x != window_dim.x || y != window_dim.y) { |         if (x != window_dim.x || y != window_dim.y) { | ||||||
|                 XMoveWindow(xctx.dpy, xctx.win.xwin, x, y); |                 XMoveWindow(xctx.dpy, xctx.win.xwin, x, y); | ||||||
|         } | 
 | ||||||
|         if (width != window_dim.w || height != window_dim.h) { |                 window_dim.x = x; | ||||||
|                 XResizeWindow(xctx.dpy, xctx.win.xwin, width, height); |                 window_dim.y = y; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         window_dim.x = x; |         if (width != window_dim.w || height != window_dim.h) { | ||||||
|         window_dim.y = y; |                 XResizeWindow(xctx.dpy, xctx.win.xwin, width, height); | ||||||
|         window_dim.h = height; | 
 | ||||||
|         window_dim.w = width; |                 window_dim.h = height; | ||||||
|  |                 window_dim.w = width; | ||||||
|  |         } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void setopacity(Window win, unsigned long opacity) | static void setopacity(Window win, unsigned long opacity) | ||||||
| @ -181,6 +166,7 @@ gboolean x_mainloop_fd_check(GSource *source) | |||||||
| gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) | gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) | ||||||
| { | { | ||||||
|         bool fullscreen_now; |         bool fullscreen_now; | ||||||
|  |         screen_info *scr; | ||||||
|         XEvent ev; |         XEvent ev; | ||||||
|         unsigned int state; |         unsigned int state; | ||||||
|         while (XPending(xctx.dpy) > 0) { |         while (XPending(xctx.dpy) > 0) { | ||||||
| @ -241,6 +227,7 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer | |||||||
|                         break; |                         break; | ||||||
|                 case PropertyNotify: |                 case PropertyNotify: | ||||||
|                         fullscreen_now = have_fullscreen_window(); |                         fullscreen_now = have_fullscreen_window(); | ||||||
|  |                         scr = get_active_screen(); | ||||||
| 
 | 
 | ||||||
|                         if (fullscreen_now != fullscreen_last) { |                         if (fullscreen_now != fullscreen_last) { | ||||||
|                                 fullscreen_last = fullscreen_now; |                                 fullscreen_last = fullscreen_now; | ||||||
| @ -251,8 +238,9 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer | |||||||
|                          * to detect a focus change to another screen |                          * to detect a focus change to another screen | ||||||
|                          */ |                          */ | ||||||
|                                    && xctx.win.visible |                                    && xctx.win.visible | ||||||
|                                    && get_active_screen()->id != xctx.win.cur_screen) { |                                    && scr->id != xctx.win.cur_screen) { | ||||||
|                                 draw(); |                                 draw(); | ||||||
|  |                                 xctx.win.cur_screen = scr->id; | ||||||
|                         } |                         } | ||||||
|                         break; |                         break; | ||||||
|                 default: |                 default: | ||||||
|  | |||||||
| @ -57,7 +57,7 @@ typedef struct _color_t { | |||||||
| extern xctx_t xctx; | extern xctx_t xctx; | ||||||
| 
 | 
 | ||||||
| /* window */ | /* window */ | ||||||
| void x_win_move(int width, int height); | void x_win_move(int x, int y, int width, int height); | ||||||
| void x_win_hide(void); | void x_win_hide(void); | ||||||
| void x_win_show(void); | void x_win_show(void); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Nikos Tsipinakis
						Nikos Tsipinakis