client/screen: Add screen_get_with_geo for get the current screen with X & Y, and improve the client free placement

This commit is contained in:
Martin Duquesnoy 2008-12-13 00:47:19 +01:00
parent 4c0a33ddfc
commit dde207ebf8
4 changed files with 42 additions and 23 deletions

View File

@ -355,11 +355,13 @@ client_manage(Window w, XWindowAttributes *wa)
Window trans;
Status rettrans;
XSetWindowAttributes at;
int mx, my;
int mx, my, s;
screen_get_sel();
c = emalloc(1, sizeof(Client));
c->win = w;
c->screen = screen_get_sel();
c->screen = selscreen;
if(conf.client.place_at_mouse)
{
@ -382,6 +384,14 @@ client_manage(Window w, XWindowAttributes *wa)
{
mx = wa->x + BORDH;
my = wa->y + TBARH + INFOBARH;
s = screen_get_with_geo(mx, my);
if(s != selscreen)
{
mx += sgeo[selscreen].x - BORDH;
my += sgeo[selscreen].y - TBARH - INFOBARH;
}
}
c->ogeo.x = c->geo.x = mx;
@ -395,7 +405,7 @@ client_manage(Window w, XWindowAttributes *wa)
frame_create(c);
client_size_hints(c);
XChangeWindowAttributes(dpy, c->win, CWEventMask, &at);
XSetWindowBorderWidth(dpy, c->win, 0); /* client win must _not_ has border */
XSetWindowBorderWidth(dpy, c->win, 0); /* client win sould _not_ have borders */
mouse_grabbuttons(c, False);
if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
for(t = clients; t && t->win != trans; t = t->next);
@ -425,8 +435,6 @@ client_moveresize(Client *c, XRectangle geo, bool r)
{
CHECK(c);
int i;
/* Resize hints {{{ */
if(r)
{
@ -482,12 +490,7 @@ client_moveresize(Client *c, XRectangle geo, bool r)
c->geo = geo;
/* Set the client screen */
for(i = 0; i < screen_count(); ++i)
if(geo.x >= sgeo[i].x
&& geo.x < sgeo[i].x + sgeo[i].width
&& geo.y >= sgeo[i].y - INFOBARH - TBARH
&& geo.y < sgeo[i].y - INFOBARH - TBARH + sgeo[i].height + INFOBARH)
c->screen = i;
c->screen = screen_get_with_geo(geo.x, geo.y);
frame_moveresize(c, c->geo);
XMoveResizeWindow(dpy, c->win, BORDH, BORDH + TBARH, c->geo.width, c->geo.height);

View File

@ -480,6 +480,8 @@ void
uicb_togglefree(uicb_t cmd)
{
CHECK(sel);
if(!sel || sel->screen != screen_get_sel())
return;
sel->free = !sel->free;
sel->tile = False;

View File

@ -83,6 +83,25 @@ screen_get_geo(int s)
return geo;
}
/** Get the current screen number with
* coordinated
*\param geo Geometry for get the screen number
*\return The screen number
*/
int
screen_get_with_geo(int x, int y)
{
int i, r = 0;
for(i = 0; i < screen_count(); ++i)
if((x >= sgeo[i].x && x < sgeo[i].x + sgeo[i].width)
&& (y >= sgeo[i].y - INFOBARH - TBARH
&& y < sgeo[i].y - INFOBARH - TBARH + sgeo[i].height + INFOBARH))
r = i;
return r;
}
/** Get and set the selected screen
*\return The number of the selected screen
*/
@ -91,22 +110,16 @@ screen_get_sel(void)
{
if(XineramaIsActive(dpy))
{
/* Unused variables */
Window w;
uint du;
int x, y, d, i;
int d, u, x, y;
XQueryPointer(dpy, root, &w, &w, &x, &y, &d, &d, &du);
XQueryPointer(dpy, root, &w, &w, &x, &y, &d, &d, (uint *)&u);
for(i = 0; i < screen_count(); ++i)
if((x >= sgeo[i].x && x < sgeo[i].x + sgeo[i].width)
&& (y >= sgeo[i].y - INFOBARH - TBARH
&& y < sgeo[i].y - INFOBARH - TBARH + sgeo[i].height + INFOBARH))
selscreen = i;
return selscreen;
selscreen = screen_get_with_geo(x, y);
}
else
return 0;
return selscreen;
}
/** Init screen geo

View File

@ -198,6 +198,7 @@ void uicb_tagtransfert(uicb_t);
/* screen */
int screen_count(void);
XRectangle screen_get_geo(int s);
int screen_get_with_geo(int x, int y);
int screen_get_sel(void);
void screen_init_geo(void);