Layout: Fix uicb_set_layout.

This commit is contained in:
Martin Duquesnoy 2009-03-26 01:23:13 +01:00
parent ac7b3b0d15
commit cc54ab8819
8 changed files with 71 additions and 133 deletions

View File

@ -650,80 +650,6 @@ client_size_hints(Client *c)
return;
}
/** Swap 2 clients
* \param a First client
* \param b Second client
*/
void
client_swap(Client *a, Client *b)
{
Client *an, *bn, *ap, *bp;
int ts, tt;
XRectangle tgeo;
if(!a || !b || !a->tile || !b->tile)
return;
/* Set temp variable */
ap = a->prev;
an = a->next;
bp = b->prev;
bn = b->next;
ts = a->screen;
tt = a->tag;
tgeo = a->geo;
/* Swap client in the double linked list */
if(a == b->next)
{
a->next = b;
b->prev = a;
if((a->prev = bp))
bp->next = a;
if((b->next = an))
an->prev = b;
}
else if(b == a->next)
{
a->prev = b;
b->next = a;
if((b->prev = ap))
ap->next = b;
if((a->next = bn))
bn->prev = a;
}
else
{
if((a->next = bn))
a->next->prev = a;
if((a->prev = bp))
a->prev->next = a;
if((b->prev = ap))
b->prev->next = b;
if((b->next = an))
b->next->prev = b;
}
if(clients == a)
clients = b;
else if(clients == b)
clients = a;
/* Swap tag/screen property */
a->screen = b->screen;
b->screen = ts;
a->tag = b->tag;
b->tag = tt;
/* Swap position/size an move them */
client_moveresize(a, b->geo, False);
client_moveresize(b, tgeo, False);
return;
}
/** Raise a client
* \param c Client pointer
*/

View File

@ -74,7 +74,7 @@ cfg_opt_t root_opts[] =
cfg_opt_t line_opts[] =
{
CFG_INT_LIST("coord", "{0, 0, 0, 0}", CFGF_MULTI),
CFG_INT_LIST("coord", "{0, 0, 0, 0}", CFGF_NONE),
CFG_END()
};
@ -124,11 +124,11 @@ cfg_opt_t layout_opts[] =
cfg_opt_t layouts_opts[] =
{
CFG_STR("fg", "#FFFFFF", CFGF_NONE),
CFG_STR("bg", "#292929", CFGF_NONE),
CFG_BOOL("border", cfg_false, CFGF_NONE),
CFG_STR("system", "menu", CFGF_NONE),
CFG_SEC("layout", layout_opts, CFGF_MULTI),
CFG_STR("fg", "#FFFFFF", CFGF_NONE),
CFG_STR("bg", "#292929", CFGF_NONE),
CFG_BOOL("border", cfg_false, CFGF_NONE),
CFG_STR("system", "menu", CFGF_NONE),
CFG_SEC("layout", layout_opts, CFGF_MULTI),
CFG_END()
};
@ -262,17 +262,6 @@ cfg_opt_t opts[] =
CFG_END()
};
func_name_list_t layout_list[] =
{
{"tile_right", tile },
{"tile_left", tile_left },
{"tile_top", tile_top },
{"tile_bottom", tile_bottom },
{"tile_grid", grid },
{"max", maxlayout },
{"free", freelayout }
};
key_name_list_t key_list[] =
{
{"Control", ControlMask },

View File

@ -302,8 +302,6 @@ ewmh_manage_window_type(Client *c)
|| atom[i] == net_atom[net_wm_window_type_splash])
{
XReparentWindow(dpy, c->win, ROOT, c->geo.x, c->geo.y);
XUnmapSubwindows(dpy, c->frame);
XUnmapWindow(dpy, c->frame);
XRaiseWindow(dpy, c->win);
c->state_dock = True;
}

View File

@ -38,6 +38,9 @@ void
init(void)
{
/* First init */
ewmh_init_hints();
init_layout();
init_conf();
init_gc();
init_font();
init_cursor();
@ -147,4 +150,34 @@ init_root(void)
return;
}
/** Init layout
*/
void
init_layout(void)
{
int i;
const func_name_list_t layout_list_tmp[] =
{
{"tile_right", tile },
{"tile_left", tile_left },
{"tile_top", tile_top },
{"tile_bottom", tile_bottom },
{"tile_grid", grid },
{"grid", grid },
{"max", maxlayout },
{"maxlayout", maxlayout },
{"freelayout", freelayout },
{"free", freelayout }
};
layout_list = emalloc(LEN(layout_list_tmp), sizeof(func_name_list_t));
memset(layout_list, 0, LEN(layout_list_tmp));
for(i = 0; i < LEN(layout_list_tmp); ++i)
layout_list[i] = layout_list_tmp[i];
return;
}

View File

@ -513,34 +513,24 @@ uicb_togglemax(uicb_t cmd)
return;
}
/** Set the layout *CRAP*
/** Set the layout
* \param cmd uicb_t type
*/
void
uicb_set_layout(uicb_t cmd)
{
int i = -1;
int i, j, n;
screen_get_sel();
if(strcmp(cmd, "tile_right") == 0
|| strcmp(cmd, "tile") == 0)
i = 0;
else if(strcmp(cmd, "tile_left") == 0)
i = 1;
else if(strcmp(cmd, "tile_top") == 0)
i = 2;
else if(strcmp(cmd, "tile_bottom") == 0)
i = 3;
else if(strcmp(cmd, "tile_grid") == 0)
i = 4;
else if(strcmp(cmd, "max") == 0)
i = 5;
else if(strcmp(cmd, "free") == 0)
i = 6;
/* Set layout_list lenght */
for(n = 0; layout_list[n].name != NULL && layout_list[n].func != NULL; ++n);
if(i >= 0)
tags[selscreen][seltag[selscreen]].layout = conf.layout[i];
for(i = 0; i < n; ++i)
if(!strcmp(cmd, _strdup(layout_list[i].name)))
for(j = 0; j < LEN(conf.layout); ++j)
if(layout_list[i].func == conf.layout[j].func)
tags[selscreen][seltag[selscreen]].layout = conf.layout[j];
arrange(selscreen);

View File

@ -43,7 +43,7 @@ mouse_move(Client *c)
uint duint;
Window dw, sw;
Client *sclient;
XRectangle geo = c->geo;
XRectangle geo = c->geo, ogeo;
XEvent ev;
if(c->max || c->lmax || c->state_fullscreen || c->state_dock)
@ -72,7 +72,11 @@ mouse_move(Client *c)
if((sclient = client_gb_win(sw))
|| (sclient = client_gb_frame(sw))
|| (sclient = client_gb_titlebar(sw)))
client_swap(c, sclient);
{
ogeo = c->geo;
client_moveresize(c, sclient->geo, False);
client_moveresize(sclient, ogeo, False);
}
}
/* To move a client normally, in freelayout */
@ -99,48 +103,45 @@ mouse_move(Client *c)
/** Resize a client with the mouse
* \param c Client pointer
*/
void
mouse_resize(Client *c)
{
int ocx = c->geo.x;
int ocy = c->geo.y;
XRectangle geo = c->geo;
XRectangle geo;
XEvent ev;
if(c->max || c->lmax || c->tile
|| c->state_fullscreen || c->state_dock)
return;
if(XGrabPointer(dpy, ROOT, False, MouseMask, GrabModeAsync, GrabModeAsync,
None, cursor[CurResize], CurrentTime) != GrabSuccess)
if(XGrabPointer(dpy, ROOT, False, MouseMask, GrabModeAsync, GrabModeAsync,
None, cursor[CurResize], CurrentTime) != GrabSuccess)
return;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->geo.width + conf.client.borderheight, c->geo.height);
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->geo.width + BORDH, c->geo.height);
for(;;)
do
{
XMaskEvent(dpy, MouseMask | ExposureMask | SubstructureRedirectMask, &ev);
if(ev.type == ButtonRelease)
if(ev.type == MotionNotify)
{
if(!c->tile)
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->geo.width + conf.client.borderheight, c->geo.height);
XUngrabPointer(dpy, CurrentTime);
return;
}
else if(ev.type == MotionNotify)
{
geo.width = ((ev.xmotion.x - ocx < 1) ? 1 : ev.xmotion.x - ocx);
geo.width = ((ev.xmotion.x - ocx < 1) ? 1 : ev.xmotion.x - ocx);
geo.height = ((ev.xmotion.y - ocy < 1) ? 1 : ev.xmotion.y - ocy);
client_moveresize(c, geo, True);
XSync(dpy, False);
}
else if(ev.type == Expose)
expose(&ev.xexpose);
}
while(ev.type != ButtonRelease);
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->geo.width + conf.client.borderheight, c->geo.height);
XUngrabPointer(dpy, CurrentTime);
return;
}

View File

@ -108,6 +108,7 @@ quit(void)
IFREE(infobar);
IFREE(keys);
IFREE(func_list);
IFREE(layout_list);
/* Clean conf alloced thing {{{ */
IFREE(menulayout.item);
@ -334,8 +335,6 @@ main(int argc, char **argv)
XSetErrorHandler(errorhandler);
/* Let's Go ! */
ewmh_init_hints();
init_conf();
init();
scan();
mainloop();

View File

@ -81,6 +81,7 @@
#define TBARH ((conf.titlebar.height < BORDH) ? BORDH : conf.titlebar.height)
#define FRAMEW(w) ((w) + BORDH * 2)
#define FRAMEH(h) ((h) + (BORDH + TBARH))
#define ROUND(x) (float)((x > 0) ? x + (float)0.5 : x - (float)0.5)
#define RESHW (5 * BORDH)
#define BUTTONWH (TBARH / 2)
#define CHECK(x) if(!(x)) return
@ -144,7 +145,6 @@ void client_manage(Window w, XWindowAttributes *wa);
void client_moveresize(Client *c, XRectangle geo, Bool r);
void client_maximize(Client *c);
void client_size_hints(Client *c);
void client_swap(Client *a, Client *b);
void client_raise(Client *c);
void client_unhide(Client *c);
void client_unmanage(Client *c);
@ -280,6 +280,7 @@ void uicb_set_layout(uicb_t);
/* init.c */
void init(void);
void init_root(void);
void init_layout(void);
void init_font(void);
void init_gc(void);
void init_cursor(void);
@ -325,6 +326,7 @@ Client *sel;
/* Other */
func_name_list_t *func_list;
func_name_list_t *layout_list;
uint numlockmask;
#endif /* WMFS_H */