From: Iain Patterson Date: Mon, 9 Mar 2009 16:10:29 +0000 (+0000) Subject: Stability X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=861de251bf2b7a382733906b7ffd38a035a8f476;p=pager.git Stability Use XGetWindowAttributes() instead of XGetGeometry(). --- diff --git a/pager.c b/pager.c index c351049..e18a3d1 100644 --- a/pager.c +++ b/pager.c @@ -16,8 +16,7 @@ static int desktop = -1; static Window drag_window; static int drag_x, drag_y; static int drag_button; -static int dockapp_x, dockapp_y; -static unsigned int dockapp_width, dockapp_height, dockapp_border, dockapp_depth; +static XWindowAttributes dockapp_attr; static double aspect, scale; static int desktop_geometry_supported; @@ -94,7 +93,7 @@ void check_support() { } void enumerate_clients(client_t ***clients, unsigned long *num_clients, unsigned long *active_desktop, unsigned long *active_window) { - Window root, qroot, qparent, dockapp_root, child, *wins, client; + Window root, qroot, qparent, child, *wins, client; int x, y; unsigned int width, height, border, depth; unsigned int root_width, root_height; @@ -115,18 +114,21 @@ void enumerate_clients(client_t ***clients, unsigned long *num_clients, unsigned root_height = DisplayWidth(DADisplay, DefaultScreen(DADisplay)); } - XGetGeometry(DADisplay, DAWindow, &dockapp_root, &dockapp_x, &dockapp_y, &dockapp_width, &dockapp_height, &dockapp_border, &dockapp_depth); - scale = (double) root_width / (double) dockapp_width; - aspect = (double) root_height / (double) dockapp_height; + *num_clients = 0; + *clients = 0; - *active_window = get_atom_long(active_window_atom, XA_WINDOW, dockapp_root); + if (! XGetWindowAttributes(DADisplay, DAWindow, &dockapp_attr)) return; + scale = (double) root_width / (double) dockapp_attr.width; + aspect = (double) root_height / (double) dockapp_attr.height; + + *active_window = get_atom_long(active_window_atom, XA_WINDOW, dockapp_attr.root); *active_desktop = get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay)); if (client_list_supported) { - get_atom_longs(client_list_atom, XA_WINDOW, dockapp_root, &data, num_clients); + get_atom_longs(client_list_atom, XA_WINDOW, dockapp_attr.root, &data, num_clients); } else { - XQueryTree(DADisplay, dockapp_root, &qroot, &qparent, &wins, (unsigned int *) num_clients); + XQueryTree(DADisplay, dockapp_attr.root, &qroot, &qparent, &wins, (unsigned int *) num_clients); } *clients = (client_t **) malloc(sizeof(client_t *) * *num_clients); @@ -190,7 +192,7 @@ void destroy_clients(client_t ***clients, unsigned long num_clients) { if (! *clients) return; - for (i = 0; i < num_clients; i++) free((*clients)[i]); + for (i = 0; i < num_clients; i++) if ((*clients)[i]) free((*clients)[i]); free(*clients); } @@ -307,10 +309,10 @@ void page() { enumerate_clients(&clients, &num_clients, &active_desktop, &active_window); - pixmap = XCreatePixmap(DADisplay, DAWindow, dockapp_width, dockapp_height, dockapp_depth); + pixmap = XCreatePixmap(DADisplay, DAWindow, dockapp_attr.width, dockapp_attr.height, dockapp_attr.depth); if (active_desktop == desktop || desktop < 0) gc = active_desktopGC; else gc = inactive_desktopGC; - draw_relief(pixmap, dockapp_width, dockapp_height, gc); + draw_relief(pixmap, dockapp_attr.width, dockapp_attr.height, gc); for (i = 0; i < num_clients; i++) { if (! clients[i]->window) continue; @@ -350,7 +352,7 @@ void move(int x, int y) { if (! drag_window) return; if (x < 0 || y < 0) return; - if (x >= dockapp_width || y >= dockapp_height) return; + if (x >= dockapp_attr.width || y >= dockapp_attr.height) return; dest_x = (long) ((double) (x - drag_x) * scale); dest_y = (long) ((double) (y - drag_y) * scale); @@ -381,17 +383,17 @@ int main(int argc, char **argv) { aspect = (double) root_width / (double) root_height; if (root_width > root_height) { - dockapp_width = DOCKAPP_SIZE; - dockapp_height = (double) DOCKAPP_SIZE / aspect; + dockapp_attr.width = DOCKAPP_SIZE; + dockapp_attr.height = (double) DOCKAPP_SIZE / aspect; } else { - dockapp_height = DOCKAPP_SIZE; - dockapp_width = (double) DOCKAPP_SIZE / aspect; + dockapp_attr.height = DOCKAPP_SIZE; + dockapp_attr.width = (double) DOCKAPP_SIZE / aspect; } DAParseArguments(argc, argv, &options, 1, "OPTIONS", "pager"); DAOpenDisplay(0, argc, argv); - DACreateIcon("pager", dockapp_width, dockapp_height, argc, argv); + DACreateIcon("pager", dockapp_attr.width, dockapp_attr.height, argc, argv); DASetCallbacks(&callbacks); DASetTimeout(SPEED);