diff --git a/awesomerc.lua.in b/awesomerc.lua.in index 9d492757e..ccd5d7ea0 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -93,8 +93,9 @@ end awesome.mouse({ }, 3, function () awful.spawn(terminal) end) awesome.mouse({ }, 4, awful.tag.viewnext) awesome.mouse({ }, 5, awful.tag.viewprev) -client.mouse({ modkey }, 1, mouse.client_move) -client.mouse({ modkey }, 3, mouse.client_resize) +client.mouse({ }, 1, function (c) c:focus_set() end) +client.mouse({ modkey }, 1, function (c) c:mouse_move() end) +client.mouse({ modkey }, 3, function (c) c:mouse_resize() end) -- }}} -- {{{ Key bindings @@ -173,6 +174,7 @@ awesome.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -- {{{ Hooks -- Hook function to execute when focusing a client. function hook_focus(c) + c:raise() c:border_set({ width = 1, color = "white" }) end diff --git a/client.c b/client.c index 3590576aa..4607863b6 100644 --- a/client.c +++ b/client.c @@ -36,6 +36,7 @@ #include "titlebar.h" #include "lua.h" #include "stack.h" +#include "mouse.h" #include "layouts/floating.h" #include "common/markup.h" #include "common/xutil.h" @@ -230,11 +231,10 @@ client_ban(client_t *c) /** Give focus to client, or to first client if c is NULL * \param c client * \param screen Screen ID - * \param raise raise window if true * \return true if a window (even root) has received focus, false otherwise */ bool -client_focus(client_t *c, int screen, bool raise) +client_focus(client_t *c, int screen) { int phys_screen; @@ -261,8 +261,6 @@ client_focus(client_t *c, int screen, bool raise) titlebar_draw(c); xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT, c->win, XCB_CURRENT_TIME); - if(raise) - client_stack(c); /* since we're dropping EnterWindow events and sometimes the window * will appear under the mouse, grabbuttons */ window_grabbuttons(c->win, c->phys_screen); @@ -293,7 +291,7 @@ client_focus(client_t *c, int screen, bool raise) * relatively to the first matching in the list */ void -client_stack(client_t *c) +client_raise(client_t *c) { uint32_t config_win_vals[2]; client_node_t *node; @@ -581,7 +579,7 @@ client_setfloating(client_t *c, bool floating, layer_t layer) { c->layer = c->oldlayer; } - client_stack(c); + client_raise(c); client_saveprops(c); } } @@ -649,7 +647,7 @@ client_unmanage(client_t *c) untag_client(c, tag); if(globalconf.focus->client == c) - client_focus(NULL, c->screen, true); + client_focus(NULL, c->screen); xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win, ANY_MODIFIER); window_setstate(c->win, XCB_WM_WITHDRAWN_STATE); @@ -1032,7 +1030,17 @@ static int luaA_client_focus_set(lua_State *L) { client_t **c = luaL_checkudata(L, 1, "client"); - client_focus(*c, (*c)->screen, false); + client_focus(*c, (*c)->screen); + return 0; +} + +/** Raise a client on top of others which are on the same layer. + */ +static int +luaA_client_raise(lua_State *L) +{ + client_t **c = luaL_checkudata(L, 1, "client"); + client_raise(*c); return 0; } @@ -1141,10 +1149,13 @@ const struct luaL_reg awesome_client_meta[] = { "kill", luaA_client_kill }, { "swap", luaA_client_swap }, { "focus_set", luaA_client_focus_set }, + { "raise", luaA_client_raise }, { "redraw", luaA_client_redraw }, { "floating_set", luaA_client_floating_set }, { "floating_get", luaA_client_floating_get }, { "icon_set", luaA_client_icon_set }, + { "mouse_resize", luaA_client_mouse_resize }, + { "mouse_move", luaA_client_mouse_move }, { "__eq", luaA_client_eq }, { "__tostring", luaA_client_tostring }, { NULL, NULL } diff --git a/client.h b/client.h index de657f95f..360573afb 100644 --- a/client.h +++ b/client.h @@ -28,8 +28,8 @@ bool client_isvisible(client_t *, int); client_t * client_get_bywin(client_t *, xcb_window_t); -bool client_focus(client_t *, int, bool); -void client_stack(client_t *); +bool client_focus(client_t *, int); +void client_raise(client_t *); void client_ban(client_t *); void client_unban(client_t *); void client_manage(xcb_window_t, xcb_get_geometry_reply_t *, int); diff --git a/event.c b/event.c index 220f678be..7c018eee6 100644 --- a/event.c +++ b/event.c @@ -48,7 +48,8 @@ extern awesome_t globalconf; * \param buttons buttons list to check for */ static void -event_handle_mouse_button_press(unsigned int button, +event_handle_mouse_button_press(client_t *c, + unsigned int button, unsigned int state, button_t *buttons) { @@ -56,7 +57,15 @@ event_handle_mouse_button_press(unsigned int button, for(b = buttons; b; b = b->next) if(button == b->button && CLEANMASK(state) == b->mod && b->fct) - luaA_dofunction(globalconf.L, b->fct, 0); + { + if(c) + { + luaA_client_userdata_new(c); + luaA_dofunction(globalconf.L, b->fct, 1); + } + else + luaA_dofunction(globalconf.L, b->fct, 0); + } } /** Handle XButtonPressed events @@ -130,34 +139,21 @@ event_handle_buttonpress(void *data __attribute__ ((unused)), for(c = globalconf.clients; c; c = c->next) if(c->titlebar_sw && c->titlebar_sw->window == ev->event) { - if(!client_focus(c, c->screen, true)) - client_stack(c); - if(CLEANMASK(ev->state) == XCB_NO_SYMBOL - && ev->detail == XCB_BUTTON_INDEX_1) - window_grabbuttons(c->win, c->phys_screen); - event_handle_mouse_button_press(ev->detail, ev->state, + event_handle_mouse_button_press(c, ev->detail, ev->state, globalconf.buttons.titlebar); return 0; } if((c = client_get_bywin(globalconf.clients, ev->event))) { - if(!client_focus(c, c->screen, true)) - client_stack(c); - if(CLEANMASK(ev->state) == XCB_NO_SYMBOL - && ev->detail == XCB_BUTTON_INDEX_1) - { - xcb_allow_events(globalconf.connection, XCB_ALLOW_REPLAY_POINTER, XCB_CURRENT_TIME); - window_grabbuttons(c->win, c->phys_screen); - } - else - event_handle_mouse_button_press(ev->detail, ev->state, globalconf.buttons.client); + event_handle_mouse_button_press(c, ev->detail, ev->state, globalconf.buttons.client); + xcb_allow_events(globalconf.connection, XCB_ALLOW_REPLAY_POINTER, XCB_CURRENT_TIME); } else for(screen = 0; screen < nb_screen; screen++) if(xcb_aux_get_screen(connection, screen)->root == ev->event) { - event_handle_mouse_button_press(ev->detail, ev->state, + event_handle_mouse_button_press(NULL, ev->detail, ev->state, globalconf.buttons.root); return 0; } diff --git a/layout.c b/layout.c index e52f159e4..ba9c1096d 100644 --- a/layout.c +++ b/layout.c @@ -84,7 +84,7 @@ arrange(int screen) * client are currently focused, pick the first one in history */ if(fscreen == screen && (c = focus_get_current_client(screen))) - client_focus(c, screen, true); + client_focus(c, screen); } p_delete(&qp_r); diff --git a/lua.c b/lua.c index 9d15fe564..2425cabdf 100644 --- a/lua.c +++ b/lua.c @@ -195,7 +195,7 @@ luaA_screen_focus(lua_State *L) /* Our table begin at 0, Lua begins at 1 */ int screen = luaL_checknumber(L, 1) - 1; luaA_checkscreen(screen); - client_focus(NULL, screen, true); + client_focus(NULL, screen); return 0; } diff --git a/mouse.c b/mouse.c index bd6dc7a75..32b1f024a 100644 --- a/mouse.c +++ b/mouse.c @@ -190,12 +190,12 @@ mouse_resizebar_new(int phys_screen, int border, area_t geometry, /** Move the focused window with the mouse. */ -void -mouse_client_move(int snap) +static void +mouse_client_move(client_t *c, int snap) { int ocx, ocy, newscreen; area_t geometry; - client_t *c = globalconf.focus->client, *target; + client_t *target; layout_t *layout; simple_window_t *sw = NULL; draw_context_t *ctx; @@ -207,9 +207,6 @@ mouse_client_move(int snap) xcb_query_pointer_cookie_t query_pointer_c; xcb_screen_t *s; - if(!c) - return; - layout = layout_get_current(c->screen); s = xcb_aux_get_screen(globalconf.connection, c->phys_screen); @@ -316,13 +313,12 @@ mouse_client_move(int snap) * \param screen Screen ID * \param arg Unused */ -void -mouse_client_resize(void) +static void +mouse_client_resize(client_t *c) { int ocx = 0, ocy = 0, n; xcb_generic_event_t *ev = NULL; xcb_motion_notify_event_t *ev_motion = NULL; - client_t *c = globalconf.focus->client; tag_t **curtags; layout_t *layout; area_t area = { 0, 0, 0, 0, NULL, NULL }, geometry = { 0, 0, 0, 0, NULL, NULL }; @@ -333,14 +329,14 @@ mouse_client_resize(void) xcb_grab_pointer_reply_t *grab_pointer_r = NULL; xcb_screen_t *s; - /* only handle floating and tiled layouts */ - if(!c || c->isfixed) + if(c->isfixed) return; curtags = tags_get_current(c->screen); layout = curtags[0]->layout; s = xcb_aux_get_screen(globalconf.connection, c->phys_screen); + /* only handle floating and tiled layouts */ if(layout == layout_floating || c->isfloating) { ocx = c->geometry.x; @@ -457,6 +453,10 @@ mouse_client_resize(void) } } +/** Set mouse coordinates. + * \param The x coordinates. + * \param The y coordinates. + */ static int luaA_mouse_coords_set(lua_State *L) { @@ -469,21 +469,31 @@ luaA_mouse_coords_set(lua_State *L) return 0; } -static int -luaA_mouse_client_resize(lua_State *L __attribute__ ((unused))) +/** Resize a client with mouse. + */ +int +luaA_client_mouse_resize(lua_State *L) { - mouse_client_resize(); + client_t **c = luaL_checkudata(L, 1, "client"); + mouse_client_resize(*c); return 0; } -static int -luaA_mouse_client_move(lua_State *L) +/** Move a client with mouse. + * \param The pixel to snap. + */ +int +luaA_client_mouse_move(lua_State *L) { - int snap = luaL_optnumber(L, 1, 8); - mouse_client_move(snap); + client_t **c = luaL_checkudata(L, 1, "client"); + int snap = luaL_optnumber(L, 2, 8); + mouse_client_move(*c, snap); return 0; } +/** Get the screen number where the mouse ic. + * \return The screen number. + */ static int luaA_mouse_screen_get(lua_State *L) { @@ -511,8 +521,6 @@ const struct luaL_reg awesome_mouse_lib[] = { { "screen_get", luaA_mouse_screen_get }, { "coords_set", luaA_mouse_coords_set }, - { "client_resize", luaA_mouse_client_resize }, - { "client_move", luaA_mouse_client_move }, { NULL, NULL } }; diff --git a/mouse.h b/mouse.h index 04e433356..360f16bbd 100644 --- a/mouse.h +++ b/mouse.h @@ -22,8 +22,10 @@ #ifndef AWESOME_MOUSE_H #define AWESOME_MOUSE_H -void mouse_client_move(int); -void mouse_client_resize(void); +#include + +int luaA_client_mouse_resize(lua_State *); +int luaA_client_mouse_move(lua_State *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/widgets/tasklist.c b/widgets/tasklist.c index e933580e8..53efbb83d 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -178,7 +178,7 @@ tasklist_button_press(widget_node_t *w, statusbar_t *statusbar, xcb_button_press_event_t *ev) { button_t *b; - client_t *c, **lc; + client_t *c; Data *d = w->widget->data; int n = 0, box_width = 0, i, ci = 0; diff --git a/window.c b/window.c index c8a098dfc..5a6b54c02 100644 --- a/window.c +++ b/window.c @@ -114,33 +114,19 @@ window_grabbuttons(xcb_window_t win, int phys_screen) { button_t *b; - /* Always grab the first mouse button. */ - xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, - XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, - XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL); - xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, - XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, - XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL | XCB_MOD_MASK_LOCK); - xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, - XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, - XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL | globalconf.numlockmask); - xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, - XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, - XCB_BUTTON_INDEX_1, XCB_NO_SYMBOL | globalconf.numlockmask | XCB_MOD_MASK_LOCK); - for(b = globalconf.buttons.client; b; b = b->next) { xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, - XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, b->button, b->mod); xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, - XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, b->button, b->mod | XCB_MOD_MASK_LOCK); xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, - XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, b->button, b->mod | globalconf.numlockmask); xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, - XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE, + XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK); }