rewrite client_manage()

This commit is contained in:
Julien Danjou 2008-01-13 16:30:43 +01:00
parent 0b5e3e7cd1
commit 47ee745425
4 changed files with 59 additions and 97 deletions

104
client.c
View File

@ -230,15 +230,13 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
Window trans; Window trans;
Bool rettrans; Bool rettrans;
XWindowChanges wc; XWindowChanges wc;
Area area, darea;
Tag *tag; Tag *tag;
Rule *rule; Rule *rule;
int phys_screen = get_phys_screen(screen); int phys_screen = get_phys_screen(screen);
area = get_screen_area(screen, NULL, NULL);
c = p_new(Client, 1); c = p_new(Client, 1);
/* Initial values */
c->win = w; c->win = w;
c->geometry.x = c->f_geometry.x = c->m_geometry.x = wa->x; c->geometry.x = c->f_geometry.x = c->m_geometry.x = wa->x;
c->geometry.y = c->f_geometry.y = c->m_geometry.y = wa->y; c->geometry.y = c->f_geometry.y = c->m_geometry.y = wa->y;
@ -247,57 +245,55 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
c->oldborder = wa->border_width; c->oldborder = wa->border_width;
c->newcomer = True; c->newcomer = True;
c->border = globalconf.screens[screen].borderpx;
c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y); c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y);
move_client_to_screen(c, screen, True); /* Set windows borders */
/* update window title */
client_updatetitle(c);
if(c->geometry.width == area.width && c->geometry.height == area.height)
c->border = wa->border_width;
else
c->border = globalconf.screens[screen].borderpx;
ewmh_check_client_hints(c);
/* loadprops or apply rules if no props */
if(!client_loadprops(c, screen))
tag_client_with_rules(c);
/* if window request fullscreen mode */
if(c->geometry.width == area.width && c->geometry.height == area.height)
{
c->geometry.x = area.x;
c->geometry.y = area.y;
}
else
{
darea = get_display_area(phys_screen,
globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding);
if(c->geometry.x + c->geometry.width + 2 * c->border > darea.x + darea.width)
c->geometry.x = c->f_geometry.x = darea.x + darea.width - c->geometry.width - 2 * c->border;
if(c->geometry.y + c->geometry.height + 2 * c->border > darea.y + darea.height)
c->geometry.y = c->f_geometry.y = darea.y + darea.height - c->geometry.height - 2 * c->border;
if(c->geometry.x < darea.x)
c->geometry.x = c->f_geometry.x = darea.x;
if(c->geometry.y < darea.y)
c->geometry.y = c->f_geometry.y = darea.y;
}
/* XXX if this necessary ? */
/* set borders */
wc.border_width = c->border; wc.border_width = c->border;
XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc); XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel); XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
/* propagates border_width, if size doesn't change */ /* propagates border_width, if size doesn't change */
window_configure(c->win, c->geometry, c->border); window_configure(c->win, c->geometry, c->border);
/* update window title */
client_updatetitle(c);
/* update hints */ /* update hints */
client_updatesizehints(c); client_updatesizehints(c);
client_updatewmhints(c); client_updatewmhints(c);
/* First check clients hints */
ewmh_check_client_hints(c);
/* loadprops or apply rules if no props */
if(!client_loadprops(c, screen))
{
/* Get the client's rule */
if((rule = rule_matching_client(c)))
{
if(rule->screen != RULE_NOSCREEN)
move_client_to_screen(c, rule->screen, True);
else
move_client_to_screen(c, screen, True);
if(!tag_client_with_rule(c, rule))
tag_client_with_current_selected(c);
}
else
move_client_to_screen(c, screen, True);
/* check for transient and set tags like its parent,
* XGetTransientForHint returns 1 on success
*/
if((rettrans = XGetTransientForHint(globalconf.display, w, &trans))
&& (t = get_client_bywin(globalconf.clients, trans)))
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
if(is_client_tagged(t, tag))
tag_client(c, tag);
/* should be floating if transsient or fixed */
if(!c->isfloating)
c->isfloating = rettrans || c->isfixed;
}
XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
/* handle xshape */ /* handle xshape */
@ -307,22 +303,6 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
window_setshape(phys_screen, c->win); window_setshape(phys_screen, c->win);
} }
/* grab buttons */
window_grabbuttons(phys_screen, c->win, False, True);
/* check for transient and set tags like its parent,
* XGetTransientForHint returns 1 on success
*/
if((rettrans = XGetTransientForHint(globalconf.display, w, &trans))
&& (t = get_client_bywin(globalconf.clients, trans)))
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
if(is_client_tagged(t, tag))
tag_client(c, tag);
/* should be floating if transsient or fixed */
if(!c->isfloating)
c->isfloating = rettrans || c->isfixed;
/* save new props */ /* save new props */
client_saveprops(c); client_saveprops(c);
@ -334,16 +314,16 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
else else
client_list_append(&globalconf.clients, c); client_list_append(&globalconf.clients, c);
ewmh_update_net_client_list(phys_screen); /* focus ? */
if(globalconf.screens[c->screen].new_get_focus)
focus(c, True, c->screen);
/* some windows require this */ /* some windows require this */
XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y, XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
c->geometry.width, c->geometry.height); c->geometry.width, c->geometry.height);
if(globalconf.screens[c->screen].new_get_focus)
focus(c, True, screen);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
ewmh_update_net_client_list(phys_screen);
/* rearrange to display new window */ /* rearrange to display new window */
arrange(c->screen); arrange(c->screen);

View File

@ -35,9 +35,10 @@
#include "ewmh.h" #include "ewmh.h"
#include "client.h" #include "client.h"
#include "widget.h" #include "widget.h"
#include "xutil.h"
#include "rules.h"
#include "layouts/tile.h" #include "layouts/tile.h"
#include "layouts/floating.h" #include "layouts/floating.h"
#include "xutil.h"
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
@ -163,7 +164,7 @@ handle_event_configurerequest(XEvent * e)
client_resize(c, geometry, False); client_resize(c, geometry, False);
tag_client_with_rules(c); tag_client_with_rule(c, rule_matching_client(c));
if(old_screen != c->screen) if(old_screen != c->screen)
{ {

43
tag.c
View File

@ -93,46 +93,27 @@ tag_client_with_current_selected(Client *c)
untag_client(c, tag); untag_client(c, tag);
} }
void Bool
tag_client_with_rules(Client *c) tag_client_with_rule(Client *c, Rule *r)
{ {
Rule *r;
Tag *tag; Tag *tag;
Bool matched = False; Bool matched = False;
if((r = rule_matching_client(c))) if(!r)
{ return False;
switch(r->isfloating)
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
if(tag_match_rule(tag, r))
{ {
case Tile: matched = True;
c->isfloating = False; tag_client(c, tag);
break;
case Float:
c->isfloating = True;
client_resize(c, c->f_geometry, False);
break;
default:
break;
} }
else
untag_client(c, tag);
if(r->screen != RULE_NOSCREEN && r->screen != c->screen) return matched;
move_client_to_screen(c, r->screen, True);
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
if(tag_match_rule(tag, r))
{
matched = True;
tag_client(c, tag);
}
else
untag_client(c, tag);
if(!matched)
tag_client_with_current_selected(c);
}
} }
Tag ** Tag **
get_current_tags(int screen) get_current_tags(int screen)
{ {

2
tag.h
View File

@ -31,8 +31,8 @@ Tag ** get_current_tags(int );
void tag_client(Client *, Tag *); void tag_client(Client *, Tag *);
void untag_client(Client *, Tag *); void untag_client(Client *, Tag *);
Bool is_client_tagged(Client *, Tag *); Bool is_client_tagged(Client *, Tag *);
Bool tag_client_with_rule(Client *, Rule *r);
void tag_client_with_current_selected(Client *); void tag_client_with_current_selected(Client *);
void tag_client_with_rules(Client *);
void tag_view_only_byindex(int, int); void tag_view_only_byindex(int, int);
Uicb uicb_client_tag; Uicb uicb_client_tag;