X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=pager.c;h=4d99ae321f358498d36251dc6eb0c57474a021ca;hb=HEAD;hp=c3510491bf04c7b7f9168dd3fc173c606495d715;hpb=0aff08f0fd7d25deeee2970e6396f38a71cd1dab;p=pager.git diff --git a/pager.c b/pager.c index c351049..4d99ae3 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; @@ -57,24 +56,43 @@ void setup_atom(Atom *atom, const char *prop) { exit(111); } -void get_atom_longs(Atom atom, Atom type, Window window, long **data, unsigned long *num_items) { +/* Don't page the pager. */ +void setup_pager() { + long states = { skip_pager_state }; + char buffer[16]; + + XChangeProperty(DADisplay, DAWindow, client_state_atom, XA_ATOM, 32, PropModeAppend, (unsigned char *) &states, 1); + + if (desktop >= 0) { + if (snprintf(buffer, sizeof(buffer), "Desktop %d", desktop + 1) < 0) return; + } + else { + if (snprintf(buffer, sizeof(buffer), "All desktops") < 0) return; + } + XStoreName(DADisplay, DAWindow, buffer); +} + +int get_atom_longs(Atom atom, Atom type, Window window, long **data, unsigned long *num_items) { Atom actual; int format; unsigned long num_bytes; - XGetWindowProperty(DADisplay, window, atom, 0, 8192, False, type, &actual, &format, num_items, &num_bytes, (unsigned char **) data); + return XGetWindowProperty(DADisplay, window, atom, 0, 8192, False, type, &actual, &format, num_items, &num_bytes, (unsigned char **) data); } -long get_atom_long(Atom atom, Atom type, Window window) { +int get_atom_long(Atom atom, Atom type, Window window, long *ret) { long *data; - long ret = 0; + int status; unsigned long num_items; - get_atom_longs(atom, type, window, &data, &num_items); - if (num_items) ret = data[0]; + *ret = 0; + + status = get_atom_longs(atom, type, window, &data, &num_items); + if (status != Success) return status; + if (num_items) *ret = data[0]; XFree(data); - return ret; + return status; } void check_support() { @@ -94,7 +112,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 +133,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; + + 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_root); - *active_desktop = get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay)); + if (get_atom_long(active_window_atom, XA_WINDOW, dockapp_attr.root, (long *) active_window) != Success) *active_window = 0; + if (get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay), (long *) active_desktop) != Success) *active_desktop = 0; if (client_list_supported) { - get_atom_longs(client_list_atom, XA_WINDOW, dockapp_root, &data, num_clients); + if (get_atom_longs(client_list_atom, XA_WINDOW, dockapp_attr.root, &data, num_clients) != Success) XFree(data); } 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); @@ -146,11 +167,8 @@ void enumerate_clients(client_t ***clients, unsigned long *num_clients, unsigned if (client_list_supported) client = data[i]; else client = XmuClientWindow(DADisplay, wins[i]); - /* Don't page the pager. */ - if (client == DAWindow) continue; - /* Check the window is on our desktop (or all desktops). */ - client_desktop = get_atom_long(client_desktop_atom, XA_CARDINAL, client); + if (get_atom_long(client_desktop_atom, XA_CARDINAL, client, &client_desktop) != Success) continue; if (desktop > -1) { if (client_desktop != desktop && client_desktop != -1) continue; } @@ -164,12 +182,15 @@ void enumerate_clients(client_t ***clients, unsigned long *num_clients, unsigned /* Make sure it isn't hidden or shaded. */ draw = 1; - get_atom_longs(client_state_atom, XA_ATOM, client, &states, &num_states); - for (j = 0; j < num_states; j++) { - if (states[j] == shaded_state) height = 3.0 * scale; - if (states[j] == skip_pager_state) draw = 0; - if (states[j] == hidden_state) draw = 0; + if (get_atom_longs(client_state_atom, XA_ATOM, client, &states, &num_states) == Success) { + for (j = 0; j < num_states; j++) { + if (states[j] == shaded_state) height = 3.0 * scale; + if (states[j] == skip_pager_state) draw = 0; + if (states[j] == hidden_state) draw = 0; + } + XFree(states); } + else continue; if (! draw) continue; (*clients)[i]->window = client; @@ -190,7 +211,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); } @@ -296,6 +317,25 @@ void release(int button, int state, int x, int y) { if (button == drag_button) drag_window = 0; } +void draw_window(Pixmap pixmap, GC gc, client_t *client) { + /* Draw a blob for the window. */ + XFillRectangle(DADisplay, pixmap, gc, client->rect.x, client->rect.y, client->rect.width, client->rect.height); + if (client->rect.width < 2 || client->rect.height < 2) return; + + /* Draw a border around the window. */ + XDrawLine(DADisplay, pixmap, window_border1GC, client->rect.x, client->rect.y, client->rect.x, client->rect.y + client->rect.height - 2); + XDrawLine(DADisplay, pixmap, window_border1GC, client->rect.x + 1, client->rect.y, client->rect.x + client->rect.width - 1, client->rect.y); + XDrawLine(DADisplay, pixmap, window_border2GC, client->rect.x, client->rect.y + client->rect.height - 1, client->rect.x + client->rect.width - 1, client->rect.y + client->rect.height - 1); + XDrawLine(DADisplay, pixmap, window_border2GC, client->rect.x + client->rect.width - 1, client->rect.y + 1, client->rect.x + client->rect.width - 1, client->rect.y + client->rect.height - 2); + + if (dockapp_attr.width <= DOCKAPP_SIZE * 2) return; + if (dockapp_attr.height <= DOCKAPP_SIZE * 2) return; + + /* Draw a drop shadow. */ + XDrawLine(DADisplay, pixmap, dockapp_border2GC, client->rect.x + 1, client->rect.y + client->rect.height, client->rect.x + client->rect.width, client->rect.y + client->rect.height); + XDrawLine(DADisplay, pixmap, dockapp_border2GC, client->rect.x + client->rect.width, client->rect.y + 1, client->rect.x + client->rect.width, client->rect.y + client->rect.height); +} + void page() { Window active_window; Pixmap pixmap; @@ -307,10 +347,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; @@ -330,13 +370,7 @@ void page() { else if ((long) clients[i]->window == active_window) gc = active_windowGC; else gc = inactive_windowGC; - XFillRectangle(DADisplay, pixmap, gc, clients[i]->rect.x, clients[i]->rect.y, clients[i]->rect.width, clients[i]->rect.height); - if (clients[i]->rect.width < 2 || clients[i]->rect.height < 2) continue; - - XDrawLine(DADisplay, pixmap, window_border1GC, clients[i]->rect.x, clients[i]->rect.y, clients[i]->rect.x, clients[i]->rect.y + clients[i]->rect.height - 2); - XDrawLine(DADisplay, pixmap, window_border1GC, clients[i]->rect.x + 1, clients[i]->rect.y, clients[i]->rect.x + clients[i]->rect.width - 1, clients[i]->rect.y); - XDrawLine(DADisplay, pixmap, window_border2GC, clients[i]->rect.x, clients[i]->rect.y + clients[i]->rect.height - 1, clients[i]->rect.x + clients[i]->rect.width - 1, clients[i]->rect.y + clients[i]->rect.height - 1); - XDrawLine(DADisplay, pixmap, window_border2GC, clients[i]->rect.x + clients[i]->rect.width - 1, clients[i]->rect.y + 1, clients[i]->rect.x + clients[i]->rect.width - 1, clients[i]->rect.y + clients[i]->rect.height - 2); + draw_window(pixmap, gc, clients[i]); } destroy_clients(&clients, num_clients); @@ -350,7 +384,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 +415,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); @@ -412,9 +446,9 @@ int main(int argc, char **argv) { check_support(); - num_desktops = get_atom_long(num_desktops_atom, XA_CARDINAL, DefaultRootWindow(DADisplay)); + if (get_atom_long(num_desktops_atom, XA_CARDINAL, DefaultRootWindow(DADisplay), &num_desktops) != Success) num_desktops = 1; if (desktop == 0) { - desktop = get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay)); + if (get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay), (long *) &desktop) != Success) desktop = 0; } else if (desktop < 0) desktop = -1; else if (desktop-- > num_desktops) { @@ -424,6 +458,7 @@ int main(int argc, char **argv) { XSetErrorHandler(error_handler); setup_GCs(); + setup_pager(); DAShow(); DAEventLoop();