2 * root.c - root window management
4 * Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <xcb/xtest.h>
26 #include "common/xcursor.h"
27 #include "common/tokenize.h"
28 #include "common/xutil.h"
30 /** Send fake events. Usually the current focused client will get it.
31 * \param L The Lua VM state.
32 * \return The number of element pushed on stack.
34 * \lparam The event type: key_press, key_release, button_press, button_release
36 * \lparam The detail: in case of a key event, this is the keycode to send, in
37 * case of a button event this is the number of the button. In case of a motion
38 * event, this is a boolean value which if true make the coordinates relatives.
39 * \lparam In case of a motion event, this is the X coordinate.
40 * \lparam In case of a motion event, this is the Y coordinate.
41 * \lparam In case of a motion event, this is the screen number to move on.
42 * If not specified, the current one is used.
45 luaA_root_fake_input(lua_State
*L
)
47 if(!globalconf
.have_xtest
)
49 luaA_warn(L
, "XTest extension is not available, cannot fake input.");
54 const char *stype
= luaL_checklstring(L
, 1, &tlen
);
57 xcb_window_t root
= XCB_NONE
;
59 switch(a_tokenize(stype
, tlen
))
63 detail
= luaL_checknumber(L
, 2); /* keycode */
65 case A_TK_KEY_RELEASE
:
66 type
= XCB_KEY_RELEASE
;
67 detail
= luaL_checknumber(L
, 2); /* keycode */
69 case A_TK_BUTTON_PRESS
:
70 type
= XCB_BUTTON_PRESS
;
71 detail
= luaL_checknumber(L
, 2); /* button number */
73 case A_TK_BUTTON_RELEASE
:
74 type
= XCB_BUTTON_RELEASE
;
75 detail
= luaL_checknumber(L
, 2); /* button number */
77 case A_TK_MOTION_NOTIFY
:
78 type
= XCB_MOTION_NOTIFY
;
79 detail
= luaA_checkboolean(L
, 2); /* relative to the current position or not */
80 x
= luaL_checknumber(L
, 3);
81 y
= luaL_checknumber(L
, 4);
82 if(lua_gettop(L
) == 5 && !globalconf
.xinerama_is_active
)
84 int screen
= luaL_checknumber(L
, 5) - 1;
85 luaA_checkscreen(screen
);
86 root
= xutil_screen_get(globalconf
.connection
, screen
)->root
;
93 xcb_test_fake_input(globalconf
.connection
,
103 /** Get or set global key bindings.
104 * This binding will be available when you'll press keys on root window.
105 * \param L The Lua VM state.
106 * \return The number of element pushed on stack.
108 * \lparam An array of key bindings objects, or nothing.
109 * \lreturn The array of key bindings objects of this client.
112 luaA_root_keys(lua_State
*L
)
114 if(lua_gettop(L
) == 1)
116 luaA_key_array_set(L
, 1, &globalconf
.keys
);
118 int nscreen
= xcb_setup_roots_length(xcb_get_setup(globalconf
.connection
));
120 for(int phys_screen
= 0; phys_screen
< nscreen
; phys_screen
++)
122 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
123 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, s
->root
, XCB_BUTTON_MASK_ANY
);
124 window_grabkeys(s
->root
, &globalconf
.keys
);
128 return luaA_key_array_get(L
, &globalconf
.keys
);
131 /** Get or set global mouse bindings.
132 * This binding will be available when you'll click on root window.
133 * \param L The Lua VM state.
134 * \return The number of element pushed on stack.
136 * \lparam An array of mouse button bindings objects, or nothing.
137 * \lreturn The array of mouse button bindings objects.
140 luaA_root_buttons(lua_State
*L
)
142 if(lua_gettop(L
) == 1)
143 luaA_button_array_set(L
, 1, &globalconf
.buttons
);
145 return luaA_button_array_get(L
, &globalconf
.buttons
);
148 /** Set the root cursor.
149 * \param L The Lua VM state.
150 * \return The number of element pushed on stack.
152 * \lparam A X cursor name.
155 luaA_root_cursor(lua_State
*L
)
157 const char *cursor_name
= luaL_checkstring(L
, 1);
158 uint16_t cursor_font
= xcursor_font_fromstr(cursor_name
);
162 uint32_t change_win_vals
[] = { xcursor_new(globalconf
.connection
, cursor_font
) };
164 for(int screen_nbr
= 0;
165 screen_nbr
< xcb_setup_roots_length(xcb_get_setup(globalconf
.connection
));
167 xcb_change_window_attributes(globalconf
.connection
,
168 xutil_screen_get(globalconf
.connection
, screen_nbr
)->root
,
173 luaA_warn(L
, "invalid cursor %s", cursor_name
);
178 const struct luaL_reg awesome_root_lib
[] =
180 { "buttons", luaA_root_buttons
},
181 { "keys", luaA_root_keys
},
182 { "cursor", luaA_root_cursor
},
183 { "fake_input", luaA_root_fake_input
},
187 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80