Change screen_get_bycoord() proto to take ScreensInfo as arg, and speed up things

This commit is contained in:
Julien Danjou 2008-03-13 09:28:21 +01:00
parent 0bde5c9e29
commit 355b7d67b3
12 changed files with 35 additions and 47 deletions

View File

@ -87,7 +87,7 @@ scan()
continue; continue;
if(wa.map_state == IsViewable || window_getstate(wins[i]) == IconicState) 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); client_manage(wins[i], &wa, real_screen);
} }
} }
@ -99,7 +99,7 @@ scan()
if(XGetTransientForHint(globalconf.display, wins[i], &d1) if(XGetTransientForHint(globalconf.display, wins[i], &d1)
&& (wa.map_state == IsViewable || window_getstate(wins[i]) == IconicState)) && (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); client_manage(wins[i], &wa, real_screen);
} }
} }
@ -194,7 +194,6 @@ main(int argc, char *argv[])
struct sockaddr_un *addr; struct sockaddr_un *addr;
Client *c; Client *c;
XSetWindowAttributes wa; XSetWindowAttributes wa;
ScreensInfo *si;
static struct option long_options[] = static struct option long_options[] =
{ {
{"help", 0, NULL, 'h'}, {"help", 0, NULL, 'h'},
@ -266,9 +265,8 @@ main(int argc, char *argv[])
ewmh_init_atoms(); ewmh_init_atoms();
/* init screens struct */ /* init screens struct */
si = screensinfo_new(dpy); globalconf.screens_info = screensinfo_new(dpy);
globalconf.nscreen = si->nscreen; globalconf.screens = p_new(VirtScreen, globalconf.screens_info->nscreen);
globalconf.screens = p_new(VirtScreen, si->nscreen);
focus_add_client(NULL); focus_add_client(NULL);
/* parse config */ /* parse config */
@ -280,17 +278,15 @@ main(int argc, char *argv[])
globalconf.cursor[CurMove] = XCreateFontCursor(globalconf.display, XC_fleur); globalconf.cursor[CurMove] = XCreateFontCursor(globalconf.display, XC_fleur);
/* for each virtual screen */ /* 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 */ /* view at least one tag */
tag_view(globalconf.screens[screen].tags, True); tag_view(globalconf.screens[screen].tags, True);
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
statusbar_init(statusbar); statusbar_init(statusbar);
} }
printf("100 %p\n", globalconf.screens_info->geometry);
screensinfo_delete(&si);
/* select for events */ /* select for events */
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
@ -312,6 +308,7 @@ main(int argc, char *argv[])
window_root_grabkeys(screen); window_root_grabkeys(screen);
} }
printf("200 %p %d\n", globalconf.screens_info->geometry, globalconf.screens_info->nscreen);
/* scan existing windows */ /* scan existing windows */
scan(); scan();

View File

@ -263,7 +263,7 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
c = p_new(Client, 1); 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, screen_geom = screen_get_area(c->screen,
globalconf.screens[screen].statusbar, 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 if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
|| c->geometry.width != geometry.width || c->geometry.height != geometry.height) || 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.x = wc.x = geometry.x;
c->geometry.y = wc.y = geometry.y; c->geometry.y = wc.y = geometry.y;

View File

@ -30,27 +30,20 @@
* \return screen number or DefaultScreen of disp on no match * \return screen number or DefaultScreen of disp on no match
*/ */
int 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; int i;
ScreensInfo *si;
/* don't waste our time */ /* don't waste our time */
if(!XineramaIsActive(disp)) if(!si->xinerama_is_active)
return screen; return screen;
/* XXX si should be an arg instead of disp */
si = screensinfo_new(disp);
for(i = 0; i < si->nscreen; i++) for(i = 0; i < si->nscreen; i++)
if((x < 0 || (x >= si->geometry[i].x && x < si->geometry[i].x + si->geometry[i].width)) 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))) && (y < 0 || (y >= si->geometry[i].y && y < si->geometry[i].y + si->geometry[i].height)))
{
screensinfo_delete(&si);
return i; return i;
}
screensinfo_delete(&si); return screen;
return DefaultScreen(disp);
} }
static inline Area static inline Area
@ -84,7 +77,7 @@ screensinfo_new(Display *disp)
si = p_new(ScreensInfo, 1); si = p_new(ScreensInfo, 1);
if(XineramaIsActive(disp)) if((si->xinerama_is_active = XineramaIsActive(disp)))
{ {
xsi = XineramaQueryScreens(disp, &xinerama_screen_number); xsi = XineramaQueryScreens(disp, &xinerama_screen_number);
si->geometry = p_new(Area, xinerama_screen_number); si->geometry = p_new(Area, xinerama_screen_number);

View File

@ -27,12 +27,13 @@
typedef struct typedef struct
{ {
int nscreen; int nscreen;
Bool xinerama_is_active;
Area *geometry; Area *geometry;
} ScreensInfo; } ScreensInfo;
int screen_get_bycoord(Display *, int, int, int); int screen_get_bycoord(ScreensInfo *, int, int, int);
void screensinfo_delete(ScreensInfo **); void screensinfo_delete(ScreensInfo **);
ScreensInfo *screensinfo_new(Display *); ScreensInfo * screensinfo_new(Display *);
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -514,7 +514,7 @@ config_parse(const char *confpatharg)
} }
/* get the right screen section */ /* 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); config_parse_screen(cfg, screen);
/* get general sections */ /* get general sections */
@ -537,7 +537,7 @@ config_parse(const char *confpatharg)
rule->screen = cfg_getint(cfgsectmp, "screen"); rule->screen = cfg_getint(cfgsectmp, "screen");
rule->ismaster = rules_get_fuzzy_from_str(cfg_getstr(cfgsectmp, "master")); rule->ismaster = rules_get_fuzzy_from_str(cfg_getstr(cfgsectmp, "master"));
rule->opacity = cfg_getfloat(cfgsectmp, "opacity"); rule->opacity = cfg_getfloat(cfgsectmp, "opacity");
if(rule->screen >= globalconf.nscreen) if(rule->screen >= globalconf.screens_info->nscreen)
rule->screen = 0; rule->screen = 0;
rule_list_push(&globalconf.rules, rule); rule_list_push(&globalconf.rules, rule);

10
event.c
View File

@ -80,7 +80,7 @@ event_handle_buttonpress(XEvent *e)
Statusbar *statusbar; Statusbar *statusbar;
XButtonPressedEvent *ev = &e->xbutton; 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) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
if(statusbar->sw->window == ev->window || statusbar->sw->window == ev->subwindow) if(statusbar->sw->window == ev->window || statusbar->sw->window == ev->subwindow)
{ {
@ -145,7 +145,7 @@ event_handle_buttonpress(XEvent *e)
&wdummy, &x, &y, &i, &wdummy, &x, &y, &i,
&i, &udummy)) &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, event_handle_mouse_button_press(screen, ev->button, ev->state,
globalconf.buttons.root, NULL); globalconf.buttons.root, NULL);
return; return;
@ -292,7 +292,7 @@ event_handle_expose(XEvent *e)
Statusbar *statusbar; Statusbar *statusbar;
if(!ev->count) 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) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
if(statusbar->sw->window == ev->window) 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 * only screen in Xinerama, so we can ask for a better screen
* number with screen_get_bycoord: we'll get 0 in Zaphod mode * number with screen_get_bycoord: we'll get 0 in Zaphod mode
* so it's the same, or maybe the real Xinerama screen */ * 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; break;
} }
@ -384,7 +384,7 @@ event_handle_maprequest(XEvent *e)
if(XineramaIsActive(globalconf.display) if(XineramaIsActive(globalconf.display)
&& XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen), && XQueryPointer(e->xany.display, RootWindow(e->xany.display, screen),
&dummy, &dummy, &x, &y, &d, &d, &m)) &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 else
for(screen = 0; wa.screen != ScreenOfDisplay(e->xany.display, screen); screen++); for(screen = 0; wa.screen != ScreenOfDisplay(e->xany.display, screen); screen++);

View File

@ -94,7 +94,7 @@ layout_refresh(void)
int screen; int screen;
int arranged = 0; 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) if(globalconf.screens[screen].need_arrange)
{ {
arrange(screen); arrange(screen);

View File

@ -117,7 +117,7 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
XQueryPointer(globalconf.display, XQueryPointer(globalconf.display,
RootWindow(globalconf.display, phys_screen), RootWindow(globalconf.display, phys_screen),
&dummy, &child, &x, &y, &di, &di, &dui); &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); move_client_to_screen(c, newscreen, True);
globalconf.screens[c->screen].need_arrange = True; globalconf.screens[c->screen].need_arrange = True;

View File

@ -38,11 +38,9 @@ extern AwesomeConf globalconf;
Area Area
screen_get_area(int screen, Statusbar *statusbar, Padding *padding) screen_get_area(int screen, Statusbar *statusbar, Padding *padding)
{ {
Area area; Area area = globalconf.screens_info->geometry[screen];
Statusbar *sb; Statusbar *sb;
area = globalconf.screens[screen].geometry;
/* make padding corrections */ /* make padding corrections */
if(padding) if(padding)
{ {
@ -246,8 +244,8 @@ uicb_screen_focus(int screen, char *arg)
new_screen = screen + 1; new_screen = screen + 1;
if (new_screen < 0) if (new_screen < 0)
new_screen = globalconf.nscreen - 1; new_screen = globalconf.screens_info->nscreen - 1;
if (new_screen > (globalconf.nscreen - 1)) if (new_screen > (globalconf.screens_info->nscreen - 1))
new_screen = 0; new_screen = 0;
client_focus(NULL, new_screen, True); client_focus(NULL, new_screen, True);
@ -274,10 +272,10 @@ uicb_client_movetoscreen(int screen __attribute__ ((unused)), char *arg)
else else
new_screen = sel->screen + 1; new_screen = sel->screen + 1;
if(new_screen >= globalconf.nscreen) if(new_screen >= globalconf.screens_info->nscreen)
new_screen = 0; new_screen = 0;
else if(new_screen < 0) else if(new_screen < 0)
new_screen = globalconf.nscreen - 1; new_screen = globalconf.screens_info->nscreen - 1;
prev_screen = sel->screen; prev_screen = sel->screen;
move_client_to_screen(sel, new_screen, True); move_client_to_screen(sel, new_screen, True);

View File

@ -238,7 +238,7 @@ statusbar_refresh()
Statusbar *statusbar; Statusbar *statusbar;
Widget *widget; Widget *widget;
for(screen = 0; screen < globalconf.nscreen; screen++) for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
for(statusbar = globalconf.screens[screen].statusbar; for(statusbar = globalconf.screens[screen].statusbar;
statusbar; statusbar;
statusbar = statusbar->next) statusbar = statusbar->next)

View File

@ -26,6 +26,7 @@
#include "layout.h" #include "layout.h"
#include "common/draw.h" #include "common/draw.h"
#include "common/swindow.h" #include "common/swindow.h"
#include "common/xscreen.h"
/** Bar possible position */ /** Bar possible position */
typedef enum typedef enum
@ -265,8 +266,6 @@ typedef struct
typedef Area (FloatingPlacement)(Area, int, int); typedef Area (FloatingPlacement)(Area, int, int);
typedef struct typedef struct
{ {
/** Screen geometry */
Area geometry;
/** Number of pixels to snap windows */ /** Number of pixels to snap windows */
int snap; int snap;
/** Border size */ /** Border size */
@ -317,8 +316,8 @@ struct AwesomeConf
Display *display; Display *display;
/** Logical screens */ /** Logical screens */
VirtScreen *screens; VirtScreen *screens;
/** Number of logical screens */ /** Screens info */
int nscreen; ScreensInfo *screens_info;
/** Rules list */ /** Rules list */
Rule *rules; Rule *rules;
/** Keys bindings list */ /** Keys bindings list */

2
uicb.c
View File

@ -127,7 +127,7 @@ run_uicb(char *cmd)
return -1; return -1;
} }
screen = atoi(cmd); screen = atoi(cmd);
if(screen >= globalconf.nscreen || screen < 0) if(screen >= globalconf.screens_info->nscreen || screen < 0)
{ {
warn("Invalid screen specified: %i\n", screen); warn("Invalid screen specified: %i\n", screen);
return -1; return -1;