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;
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();

View File

@ -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;

View File

@ -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);

View File

@ -27,10 +27,11 @@
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 *);

View File

@ -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);

10
event.c
View File

@ -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++);

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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)

View File

@ -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 */

2
uicb.c
View File

@ -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;