From 355b7d67b33bbeb43827f3caa4cf716aa427beb2 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 13 Mar 2008 09:28:21 +0100 Subject: [PATCH] Change screen_get_bycoord() proto to take ScreensInfo as arg, and speed up things --- awesome.c | 17 +++++++---------- client.c | 4 ++-- common/xscreen.c | 15 ++++----------- common/xscreen.h | 5 +++-- config.c | 4 ++-- event.c | 10 +++++----- layout.c | 2 +- mouse.c | 2 +- screen.c | 12 +++++------- statusbar.c | 2 +- structs.h | 7 +++---- uicb.c | 2 +- 12 files changed, 35 insertions(+), 47 deletions(-) diff --git a/awesome.c b/awesome.c index 6ec07343d..17cd6a461 100644 --- a/awesome.c +++ b/awesome.c @@ -87,7 +87,7 @@ scan() continue; if(wa.map_state == IsViewable || window_getstate(wins[i]) == IconicState) { - real_screen = screen_get_bycoord(globalconf.display, screen, wa.x, wa.y); + real_screen = screen_get_bycoord(globalconf.screens_info, screen, wa.x, wa.y); client_manage(wins[i], &wa, real_screen); } } @@ -99,7 +99,7 @@ scan() if(XGetTransientForHint(globalconf.display, wins[i], &d1) && (wa.map_state == IsViewable || window_getstate(wins[i]) == IconicState)) { - real_screen = screen_get_bycoord(globalconf.display, screen, wa.x, wa.y); + real_screen = screen_get_bycoord(globalconf.screens_info, screen, wa.x, wa.y); client_manage(wins[i], &wa, real_screen); } } @@ -194,7 +194,6 @@ main(int argc, char *argv[]) struct sockaddr_un *addr; Client *c; XSetWindowAttributes wa; - ScreensInfo *si; static struct option long_options[] = { {"help", 0, NULL, 'h'}, @@ -266,9 +265,8 @@ main(int argc, char *argv[]) ewmh_init_atoms(); /* init screens struct */ - si = screensinfo_new(dpy); - globalconf.nscreen = si->nscreen; - globalconf.screens = p_new(VirtScreen, si->nscreen); + globalconf.screens_info = screensinfo_new(dpy); + globalconf.screens = p_new(VirtScreen, globalconf.screens_info->nscreen); focus_add_client(NULL); /* parse config */ @@ -280,17 +278,15 @@ main(int argc, char *argv[]) globalconf.cursor[CurMove] = XCreateFontCursor(globalconf.display, XC_fleur); /* for each virtual screen */ - for(screen = 0; screen < globalconf.nscreen; screen++) + for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) { - globalconf.screens[screen].geometry = si->geometry[screen]; /* view at least one tag */ tag_view(globalconf.screens[screen].tags, True); for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) statusbar_init(statusbar); } - - screensinfo_delete(&si); + printf("100 %p\n", globalconf.screens_info->geometry); /* select for events */ wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask @@ -312,6 +308,7 @@ main(int argc, char *argv[]) window_root_grabkeys(screen); } + printf("200 %p %d\n", globalconf.screens_info->geometry, globalconf.screens_info->nscreen); /* scan existing windows */ scan(); diff --git a/client.c b/client.c index bacf9543e..f1e108712 100644 --- a/client.c +++ b/client.c @@ -263,7 +263,7 @@ client_manage(Window w, XWindowAttributes *wa, int screen) c = p_new(Client, 1); - c->screen = screen_get_bycoord(globalconf.display, screen, wa->x, wa->y); + c->screen = screen_get_bycoord(globalconf.screens_info, screen, wa->x, wa->y); screen_geom = screen_get_area(c->screen, globalconf.screens[screen].statusbar, @@ -460,7 +460,7 @@ client_resize(Client *c, Area geometry, Bool sizehints) if(c->geometry.x != geometry.x || c->geometry.y != geometry.y || c->geometry.width != geometry.width || c->geometry.height != geometry.height) { - new_screen = screen_get_bycoord(globalconf.display, c->screen, geometry.x, geometry.y); + new_screen = screen_get_bycoord(globalconf.screens_info, c->screen, geometry.x, geometry.y); c->geometry.x = wc.x = geometry.x; c->geometry.y = wc.y = geometry.y; diff --git a/common/xscreen.c b/common/xscreen.c index 6faa5c32b..a8b8c9385 100644 --- a/common/xscreen.c +++ b/common/xscreen.c @@ -30,27 +30,20 @@ * \return screen number or DefaultScreen of disp on no match */ int -screen_get_bycoord(Display *disp, int screen, int x, int y) +screen_get_bycoord(ScreensInfo *si, int screen, int x, int y) { int i; - ScreensInfo *si; /* don't waste our time */ - if(!XineramaIsActive(disp)) + if(!si->xinerama_is_active) return screen; - /* XXX si should be an arg instead of disp */ - si = screensinfo_new(disp); for(i = 0; i < si->nscreen; i++) if((x < 0 || (x >= si->geometry[i].x && x < si->geometry[i].x + si->geometry[i].width)) && (y < 0 || (y >= si->geometry[i].y && y < si->geometry[i].y + si->geometry[i].height))) - { - screensinfo_delete(&si); return i; - } - screensinfo_delete(&si); - return DefaultScreen(disp); + return screen; } static inline Area @@ -84,7 +77,7 @@ screensinfo_new(Display *disp) si = p_new(ScreensInfo, 1); - if(XineramaIsActive(disp)) + if((si->xinerama_is_active = XineramaIsActive(disp))) { xsi = XineramaQueryScreens(disp, &xinerama_screen_number); si->geometry = p_new(Area, xinerama_screen_number); diff --git a/common/xscreen.h b/common/xscreen.h index d6fa47849..cb69ab0c1 100644 --- a/common/xscreen.h +++ b/common/xscreen.h @@ -27,12 +27,13 @@ typedef struct { int nscreen; + Bool xinerama_is_active; Area *geometry; } ScreensInfo; -int screen_get_bycoord(Display *, int, int, int); +int screen_get_bycoord(ScreensInfo *, int, int, int); void screensinfo_delete(ScreensInfo **); -ScreensInfo *screensinfo_new(Display *); +ScreensInfo * screensinfo_new(Display *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/config.c b/config.c index 3768887ab..4fe388714 100644 --- a/config.c +++ b/config.c @@ -514,7 +514,7 @@ config_parse(const char *confpatharg) } /* get the right screen section */ - for(screen = 0; screen < globalconf.nscreen; screen++) + for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) config_parse_screen(cfg, screen); /* get general sections */ @@ -537,7 +537,7 @@ config_parse(const char *confpatharg) rule->screen = cfg_getint(cfgsectmp, "screen"); rule->ismaster = rules_get_fuzzy_from_str(cfg_getstr(cfgsectmp, "master")); rule->opacity = cfg_getfloat(cfgsectmp, "opacity"); - if(rule->screen >= globalconf.nscreen) + if(rule->screen >= globalconf.screens_info->nscreen) rule->screen = 0; rule_list_push(&globalconf.rules, rule); diff --git a/event.c b/event.c index f57bf7561..5d3b37907 100644 --- a/event.c +++ b/event.c @@ -80,7 +80,7 @@ event_handle_buttonpress(XEvent *e) Statusbar *statusbar; XButtonPressedEvent *ev = &e->xbutton; - for(screen = 0; screen < globalconf.nscreen; screen++) + for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) if(statusbar->sw->window == ev->window || statusbar->sw->window == ev->subwindow) { @@ -145,7 +145,7 @@ event_handle_buttonpress(XEvent *e) &wdummy, &x, &y, &i, &i, &udummy)) { - screen = screen_get_bycoord(globalconf.display, screen, x, y); + screen = screen_get_bycoord(globalconf.screens_info, screen, x, y); event_handle_mouse_button_press(screen, ev->button, ev->state, globalconf.buttons.root, NULL); return; @@ -292,7 +292,7 @@ event_handle_expose(XEvent *e) Statusbar *statusbar; if(!ev->count) - for(screen = 0; screen < globalconf.nscreen; screen++) + for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) if(statusbar->sw->window == ev->window) { @@ -321,7 +321,7 @@ event_handle_keypress(XEvent *e) * only screen in Xinerama, so we can ask for a better screen * number with screen_get_bycoord: we'll get 0 in Zaphod mode * so it's the same, or maybe the real Xinerama screen */ - screen = screen_get_bycoord(globalconf.display, screen, x, y); + screen = screen_get_bycoord(globalconf.screens_info, screen, x, y); break; } @@ -384,7 +384,7 @@ event_handle_maprequest(XEvent *e) if(XineramaIsActive(globalconf.display) && XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen), &dummy, &dummy, &x, &y, &d, &d, &m)) - screen = screen_get_bycoord(globalconf.display, screen, x, y); + screen = screen_get_bycoord(globalconf.screens_info, screen, x, y); else for(screen = 0; wa.screen != ScreenOfDisplay(e->xany.display, screen); screen++); diff --git a/layout.c b/layout.c index d4b1491b4..cde08bf3c 100644 --- a/layout.c +++ b/layout.c @@ -94,7 +94,7 @@ layout_refresh(void) int screen; int arranged = 0; - for(screen = 0; screen < globalconf.nscreen; screen++) + for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) if(globalconf.screens[screen].need_arrange) { arrange(screen); diff --git a/mouse.c b/mouse.c index baf8c04f5..a532f90f4 100644 --- a/mouse.c +++ b/mouse.c @@ -117,7 +117,7 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused))) XQueryPointer(globalconf.display, RootWindow(globalconf.display, phys_screen), &dummy, &child, &x, &y, &di, &di, &dui); - if((newscreen = screen_get_bycoord(globalconf.display, c->screen, x, y)) != c->screen) + if((newscreen = screen_get_bycoord(globalconf.screens_info, c->screen, x, y)) != c->screen) { move_client_to_screen(c, newscreen, True); globalconf.screens[c->screen].need_arrange = True; diff --git a/screen.c b/screen.c index 76eb05c94..27d0a0444 100644 --- a/screen.c +++ b/screen.c @@ -38,11 +38,9 @@ extern AwesomeConf globalconf; Area screen_get_area(int screen, Statusbar *statusbar, Padding *padding) { - Area area; + Area area = globalconf.screens_info->geometry[screen]; Statusbar *sb; - area = globalconf.screens[screen].geometry; - /* make padding corrections */ if(padding) { @@ -246,8 +244,8 @@ uicb_screen_focus(int screen, char *arg) new_screen = screen + 1; if (new_screen < 0) - new_screen = globalconf.nscreen - 1; - if (new_screen > (globalconf.nscreen - 1)) + new_screen = globalconf.screens_info->nscreen - 1; + if (new_screen > (globalconf.screens_info->nscreen - 1)) new_screen = 0; client_focus(NULL, new_screen, True); @@ -274,10 +272,10 @@ uicb_client_movetoscreen(int screen __attribute__ ((unused)), char *arg) else new_screen = sel->screen + 1; - if(new_screen >= globalconf.nscreen) + if(new_screen >= globalconf.screens_info->nscreen) new_screen = 0; else if(new_screen < 0) - new_screen = globalconf.nscreen - 1; + new_screen = globalconf.screens_info->nscreen - 1; prev_screen = sel->screen; move_client_to_screen(sel, new_screen, True); diff --git a/statusbar.c b/statusbar.c index e84a4d754..eb34c57f0 100644 --- a/statusbar.c +++ b/statusbar.c @@ -238,7 +238,7 @@ statusbar_refresh() Statusbar *statusbar; Widget *widget; - for(screen = 0; screen < globalconf.nscreen; screen++) + for(screen = 0; screen < globalconf.screens_info->nscreen; screen++) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) diff --git a/structs.h b/structs.h index bb73e1ab2..fdb7be7f4 100644 --- a/structs.h +++ b/structs.h @@ -26,6 +26,7 @@ #include "layout.h" #include "common/draw.h" #include "common/swindow.h" +#include "common/xscreen.h" /** Bar possible position */ typedef enum @@ -265,8 +266,6 @@ typedef struct typedef Area (FloatingPlacement)(Area, int, int); typedef struct { - /** Screen geometry */ - Area geometry; /** Number of pixels to snap windows */ int snap; /** Border size */ @@ -317,8 +316,8 @@ struct AwesomeConf Display *display; /** Logical screens */ VirtScreen *screens; - /** Number of logical screens */ - int nscreen; + /** Screens info */ + ScreensInfo *screens_info; /** Rules list */ Rule *rules; /** Keys bindings list */ diff --git a/uicb.c b/uicb.c index 33e29f68b..bdb8978e1 100644 --- a/uicb.c +++ b/uicb.c @@ -127,7 +127,7 @@ run_uicb(char *cmd) return -1; } screen = atoi(cmd); - if(screen >= globalconf.nscreen || screen < 0) + if(screen >= globalconf.screens_info->nscreen || screen < 0) { warn("Invalid screen specified: %i\n", screen); return -1;