[client] Rework raise and mouse stuff

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-26 16:17:57 +02:00
parent a5c00cca24
commit 0e3531d3a3
10 changed files with 79 additions and 74 deletions

View File

@ -93,8 +93,9 @@ end
awesome.mouse({ }, 3, function () awful.spawn(terminal) end) awesome.mouse({ }, 3, function () awful.spawn(terminal) end)
awesome.mouse({ }, 4, awful.tag.viewnext) awesome.mouse({ }, 4, awful.tag.viewnext)
awesome.mouse({ }, 5, awful.tag.viewprev) awesome.mouse({ }, 5, awful.tag.viewprev)
client.mouse({ modkey }, 1, mouse.client_move) client.mouse({ }, 1, function (c) c:focus_set() end)
client.mouse({ modkey }, 3, mouse.client_resize) client.mouse({ modkey }, 1, function (c) c:mouse_move() end)
client.mouse({ modkey }, 3, function (c) c:mouse_resize() end)
-- }}} -- }}}
-- {{{ Key bindings -- {{{ Key bindings
@ -173,6 +174,7 @@ awesome.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts,
-- {{{ Hooks -- {{{ Hooks
-- Hook function to execute when focusing a client. -- Hook function to execute when focusing a client.
function hook_focus(c) function hook_focus(c)
c:raise()
c:border_set({ width = 1, color = "white" }) c:border_set({ width = 1, color = "white" })
end end

View File

@ -36,6 +36,7 @@
#include "titlebar.h" #include "titlebar.h"
#include "lua.h" #include "lua.h"
#include "stack.h" #include "stack.h"
#include "mouse.h"
#include "layouts/floating.h" #include "layouts/floating.h"
#include "common/markup.h" #include "common/markup.h"
#include "common/xutil.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 /** Give focus to client, or to first client if c is NULL
* \param c client * \param c client
* \param screen Screen ID * \param screen Screen ID
* \param raise raise window if true
* \return true if a window (even root) has received focus, false otherwise * \return true if a window (even root) has received focus, false otherwise
*/ */
bool bool
client_focus(client_t *c, int screen, bool raise) client_focus(client_t *c, int screen)
{ {
int phys_screen; int phys_screen;
@ -261,8 +261,6 @@ client_focus(client_t *c, int screen, bool raise)
titlebar_draw(c); titlebar_draw(c);
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT, xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
c->win, XCB_CURRENT_TIME); c->win, XCB_CURRENT_TIME);
if(raise)
client_stack(c);
/* since we're dropping EnterWindow events and sometimes the window /* since we're dropping EnterWindow events and sometimes the window
* will appear under the mouse, grabbuttons */ * will appear under the mouse, grabbuttons */
window_grabbuttons(c->win, c->phys_screen); 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 * relatively to the first matching in the list
*/ */
void void
client_stack(client_t *c) client_raise(client_t *c)
{ {
uint32_t config_win_vals[2]; uint32_t config_win_vals[2];
client_node_t *node; client_node_t *node;
@ -581,7 +579,7 @@ client_setfloating(client_t *c, bool floating, layer_t layer)
{ {
c->layer = c->oldlayer; c->layer = c->oldlayer;
} }
client_stack(c); client_raise(c);
client_saveprops(c); client_saveprops(c);
} }
} }
@ -649,7 +647,7 @@ client_unmanage(client_t *c)
untag_client(c, tag); untag_client(c, tag);
if(globalconf.focus->client == c) 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); xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win, ANY_MODIFIER);
window_setstate(c->win, XCB_WM_WITHDRAWN_STATE); window_setstate(c->win, XCB_WM_WITHDRAWN_STATE);
@ -1032,7 +1030,17 @@ static int
luaA_client_focus_set(lua_State *L) luaA_client_focus_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); 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; return 0;
} }
@ -1141,10 +1149,13 @@ const struct luaL_reg awesome_client_meta[] =
{ "kill", luaA_client_kill }, { "kill", luaA_client_kill },
{ "swap", luaA_client_swap }, { "swap", luaA_client_swap },
{ "focus_set", luaA_client_focus_set }, { "focus_set", luaA_client_focus_set },
{ "raise", luaA_client_raise },
{ "redraw", luaA_client_redraw }, { "redraw", luaA_client_redraw },
{ "floating_set", luaA_client_floating_set }, { "floating_set", luaA_client_floating_set },
{ "floating_get", luaA_client_floating_get }, { "floating_get", luaA_client_floating_get },
{ "icon_set", luaA_client_icon_set }, { "icon_set", luaA_client_icon_set },
{ "mouse_resize", luaA_client_mouse_resize },
{ "mouse_move", luaA_client_mouse_move },
{ "__eq", luaA_client_eq }, { "__eq", luaA_client_eq },
{ "__tostring", luaA_client_tostring }, { "__tostring", luaA_client_tostring },
{ NULL, NULL } { NULL, NULL }

View File

@ -28,8 +28,8 @@
bool client_isvisible(client_t *, int); bool client_isvisible(client_t *, int);
client_t * client_get_bywin(client_t *, xcb_window_t); client_t * client_get_bywin(client_t *, xcb_window_t);
bool client_focus(client_t *, int, bool); bool client_focus(client_t *, int);
void client_stack(client_t *); void client_raise(client_t *);
void client_ban(client_t *); void client_ban(client_t *);
void client_unban(client_t *); void client_unban(client_t *);
void client_manage(xcb_window_t, xcb_get_geometry_reply_t *, int); void client_manage(xcb_window_t, xcb_get_geometry_reply_t *, int);

34
event.c
View File

@ -48,7 +48,8 @@ extern awesome_t globalconf;
* \param buttons buttons list to check for * \param buttons buttons list to check for
*/ */
static void static void
event_handle_mouse_button_press(unsigned int button, event_handle_mouse_button_press(client_t *c,
unsigned int button,
unsigned int state, unsigned int state,
button_t *buttons) button_t *buttons)
{ {
@ -56,7 +57,15 @@ event_handle_mouse_button_press(unsigned int button,
for(b = buttons; b; b = b->next) for(b = buttons; b; b = b->next)
if(button == b->button && CLEANMASK(state) == b->mod && b->fct) 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 /** Handle XButtonPressed events
@ -130,34 +139,21 @@ event_handle_buttonpress(void *data __attribute__ ((unused)),
for(c = globalconf.clients; c; c = c->next) for(c = globalconf.clients; c; c = c->next)
if(c->titlebar_sw && c->titlebar_sw->window == ev->event) if(c->titlebar_sw && c->titlebar_sw->window == ev->event)
{ {
if(!client_focus(c, c->screen, true)) event_handle_mouse_button_press(c, ev->detail, ev->state,
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,
globalconf.buttons.titlebar); globalconf.buttons.titlebar);
return 0; return 0;
} }
if((c = client_get_bywin(globalconf.clients, ev->event))) if((c = client_get_bywin(globalconf.clients, ev->event)))
{ {
if(!client_focus(c, c->screen, true)) event_handle_mouse_button_press(c, ev->detail, ev->state, globalconf.buttons.client);
client_stack(c); xcb_allow_events(globalconf.connection, XCB_ALLOW_REPLAY_POINTER, XCB_CURRENT_TIME);
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);
} }
else else
for(screen = 0; screen < nb_screen; screen++) for(screen = 0; screen < nb_screen; screen++)
if(xcb_aux_get_screen(connection, screen)->root == ev->event) 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); globalconf.buttons.root);
return 0; return 0;
} }

View File

@ -84,7 +84,7 @@ arrange(int screen)
* client are currently focused, pick the first one in history */ * client are currently focused, pick the first one in history */
if(fscreen == screen if(fscreen == screen
&& (c = focus_get_current_client(screen))) && (c = focus_get_current_client(screen)))
client_focus(c, screen, true); client_focus(c, screen);
} }
p_delete(&qp_r); p_delete(&qp_r);

2
lua.c
View File

@ -195,7 +195,7 @@ luaA_screen_focus(lua_State *L)
/* Our table begin at 0, Lua begins at 1 */ /* Our table begin at 0, Lua begins at 1 */
int screen = luaL_checknumber(L, 1) - 1; int screen = luaL_checknumber(L, 1) - 1;
luaA_checkscreen(screen); luaA_checkscreen(screen);
client_focus(NULL, screen, true); client_focus(NULL, screen);
return 0; return 0;
} }

48
mouse.c
View File

@ -190,12 +190,12 @@ mouse_resizebar_new(int phys_screen, int border, area_t geometry,
/** Move the focused window with the mouse. /** Move the focused window with the mouse.
*/ */
void static void
mouse_client_move(int snap) mouse_client_move(client_t *c, int snap)
{ {
int ocx, ocy, newscreen; int ocx, ocy, newscreen;
area_t geometry; area_t geometry;
client_t *c = globalconf.focus->client, *target; client_t *target;
layout_t *layout; layout_t *layout;
simple_window_t *sw = NULL; simple_window_t *sw = NULL;
draw_context_t *ctx; draw_context_t *ctx;
@ -207,9 +207,6 @@ mouse_client_move(int snap)
xcb_query_pointer_cookie_t query_pointer_c; xcb_query_pointer_cookie_t query_pointer_c;
xcb_screen_t *s; xcb_screen_t *s;
if(!c)
return;
layout = layout_get_current(c->screen); layout = layout_get_current(c->screen);
s = xcb_aux_get_screen(globalconf.connection, c->phys_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 screen Screen ID
* \param arg Unused * \param arg Unused
*/ */
void static void
mouse_client_resize(void) mouse_client_resize(client_t *c)
{ {
int ocx = 0, ocy = 0, n; int ocx = 0, ocy = 0, n;
xcb_generic_event_t *ev = NULL; xcb_generic_event_t *ev = NULL;
xcb_motion_notify_event_t *ev_motion = NULL; xcb_motion_notify_event_t *ev_motion = NULL;
client_t *c = globalconf.focus->client;
tag_t **curtags; tag_t **curtags;
layout_t *layout; layout_t *layout;
area_t area = { 0, 0, 0, 0, NULL, NULL }, geometry = { 0, 0, 0, 0, NULL, NULL }; 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_grab_pointer_reply_t *grab_pointer_r = NULL;
xcb_screen_t *s; xcb_screen_t *s;
/* only handle floating and tiled layouts */ if(c->isfixed)
if(!c || c->isfixed)
return; return;
curtags = tags_get_current(c->screen); curtags = tags_get_current(c->screen);
layout = curtags[0]->layout; layout = curtags[0]->layout;
s = xcb_aux_get_screen(globalconf.connection, c->phys_screen); s = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
/* only handle floating and tiled layouts */
if(layout == layout_floating || c->isfloating) if(layout == layout_floating || c->isfloating)
{ {
ocx = c->geometry.x; 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 static int
luaA_mouse_coords_set(lua_State *L) luaA_mouse_coords_set(lua_State *L)
{ {
@ -469,21 +469,31 @@ luaA_mouse_coords_set(lua_State *L)
return 0; return 0;
} }
static int /** Resize a client with mouse.
luaA_mouse_client_resize(lua_State *L __attribute__ ((unused))) */
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; return 0;
} }
static int /** Move a client with mouse.
luaA_mouse_client_move(lua_State *L) * \param The pixel to snap.
*/
int
luaA_client_mouse_move(lua_State *L)
{ {
int snap = luaL_optnumber(L, 1, 8); client_t **c = luaL_checkudata(L, 1, "client");
mouse_client_move(snap); int snap = luaL_optnumber(L, 2, 8);
mouse_client_move(*c, snap);
return 0; return 0;
} }
/** Get the screen number where the mouse ic.
* \return The screen number.
*/
static int static int
luaA_mouse_screen_get(lua_State *L) luaA_mouse_screen_get(lua_State *L)
{ {
@ -511,8 +521,6 @@ const struct luaL_reg awesome_mouse_lib[] =
{ {
{ "screen_get", luaA_mouse_screen_get }, { "screen_get", luaA_mouse_screen_get },
{ "coords_set", luaA_mouse_coords_set }, { "coords_set", luaA_mouse_coords_set },
{ "client_resize", luaA_mouse_client_resize },
{ "client_move", luaA_mouse_client_move },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -22,8 +22,10 @@
#ifndef AWESOME_MOUSE_H #ifndef AWESOME_MOUSE_H
#define AWESOME_MOUSE_H #define AWESOME_MOUSE_H
void mouse_client_move(int); #include <lua.h>
void mouse_client_resize(void);
int luaA_client_mouse_resize(lua_State *);
int luaA_client_mouse_move(lua_State *);
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -178,7 +178,7 @@ tasklist_button_press(widget_node_t *w, statusbar_t *statusbar,
xcb_button_press_event_t *ev) xcb_button_press_event_t *ev)
{ {
button_t *b; button_t *b;
client_t *c, **lc; client_t *c;
Data *d = w->widget->data; Data *d = w->widget->data;
int n = 0, box_width = 0, i, ci = 0; int n = 0, box_width = 0, i, ci = 0;

View File

@ -114,33 +114,19 @@ window_grabbuttons(xcb_window_t win, int phys_screen)
{ {
button_t *b; 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) for(b = globalconf.buttons.client; b; b = b->next)
{ {
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, 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); b->button, b->mod);
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, 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); b->button, b->mod | XCB_MOD_MASK_LOCK);
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, 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); b->button, b->mod | globalconf.numlockmask);
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK, 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); b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
} }