diff options
Diffstat (limited to 'x11.c')
| -rw-r--r-- | x11.c | 78 |
1 files changed, 62 insertions, 16 deletions
@@ -24,6 +24,10 @@ struct Window { cairo_surface_t *surface; cairo_t *cr; double dpi; + uint16_t screen_width; + uint16_t screen_height; + int x, y; + int width, height; }; static xcb_atom_t intern_atom(Window *win, const char *atom) @@ -71,6 +75,12 @@ Window *window_create(void) xcb_randr_screen_size_t *screen_size = xcb_randr_get_screen_info_sizes(info_reply); log_debug("Screen size [width=%d, height=%d]", screen_size->width, screen_size->height); + win->screen_width = screen_size->width; + win->screen_height = screen_size->height; + + win->width = win->height = 0; + win->x = win->y = 0; + xcb_randr_select_input(win->connection, win->window, XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE | @@ -131,24 +141,19 @@ found_visual: colormap // colormap }; - int width = screen_size->width * 0.98; - int height = screen_size->height * 0.03; - - width -= width % 2 != 0; - height -= height % 2 != 0; + win->width = win->height = 1; + log_debug("Window (temporary) size [width=%d, height=%d]", win->width, win->height); - log_debug("Window size [width=%d, height=%d]", width, height); - - int x = (screen_size->width - width) / 2.0; - int y = screen_size->height * 0.0125; - - log_debug("Window position [x=%d, y=%d]", x, y); + win->x = win->y = 0; + log_debug("Window (temporary) position [x=%d, y=%d]", win->x, win->y); win->window = xcb_generate_id(win->connection); xcb_create_window(win->connection, XCB_COPY_FROM_PARENT, win->window, win->screen->root, - x, y, width, height, 0, + win->x, win->y, + win->width, win->height, + 0, // border XCB_WINDOW_CLASS_INPUT_OUTPUT, win->screen->root_visual, value_mask, @@ -182,7 +187,12 @@ found_visual: xcb_flush(win->connection); log_debug("Xcb initialized"); - win->surface = cairo_xcb_surface_create(win->connection, win->window, win->visual_type, width, height); + win->surface = cairo_xcb_surface_create(win->connection, + win->window, + win->visual_type, + screen_size->width, + screen_size->height); + assert(cairo_surface_status(win->surface) == CAIRO_STATUS_SUCCESS); win->cr = cairo_create(win->surface); @@ -203,12 +213,47 @@ double window_get_scale(Window *win) return MAX(1, win->dpi/96.); } -void window_paint_surface(Window *win, cairo_surface_t *surface, int width, int height) +void window_get_screen_size(Window *win, int *width, int *height) +{ + *width = win->screen_width; + *height = win->screen_height; +} + +void window_move(Window *win, int x, int y) +{ + if (win->x == x && win->y == y) return; + + win->x = x; + win->y = y; + + const uint32_t values[] = { x, y }; + xcb_configure_window(win->connection, + win->window, + XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, + values); + + log_debug("Window (new) position [x=%d, y=%d]", win->x, win->y); +} + +void window_resize(Window *win, int width, int height) { - double scale = window_get_scale(win); + if (win->width == width && win->height == height) return; + + win->width = width; + win->height = height; - cairo_xcb_surface_set_size(win->surface, round(width * scale), round(height * scale)); + const uint32_t values[] = { width, height }; + xcb_configure_window(win->connection, + win->window, + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, + values); + log_debug("Window (new) size [width=%d, height=%d]", win->width, win->height); +} + +void window_paint_surface(Window *win, cairo_surface_t *surface, int width, int height) +{ + cairo_xcb_surface_set_size(win->surface, width, height); xcb_clear_area(win->connection, false, win->window, 0, 0, 0, 0); cairo_set_source_surface(win->cr, surface, 0, 0); @@ -222,6 +267,7 @@ void window_destroy(Window *win) { cairo_destroy(win->cr); cairo_surface_destroy(win->surface); + xcb_xrm_database_free(win->database); xcb_disconnect(win->connection); g_free(win); |
