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 /** Set the root cursor.
104 * \param L The Lua VM state.
105 * \return The number of element pushed on stack.
107 * \lparam A X cursor name.
110 luaA_root_cursor(lua_State
*L
)
112 const char *cursor_name
= luaL_checkstring(L
, 1);
113 uint16_t cursor_font
= xcursor_font_fromstr(cursor_name
);
117 uint32_t change_win_vals
[] = { xcursor_new(globalconf
.connection
, cursor_font
) };
119 for(int screen_nbr
= 0;
120 screen_nbr
< xcb_setup_roots_length(xcb_get_setup(globalconf
.connection
));
122 xcb_change_window_attributes(globalconf
.connection
,
123 xutil_screen_get(globalconf
.connection
, screen_nbr
)->root
,
128 luaA_warn(L
, "invalid cursor %s", cursor_name
);
133 /** Get the wiboxes attached to a screen.
134 * \param L The Lua VM state.
135 * \return The number of element pushed on stack.
137 * \lreturn A table with all wiboxes.
140 luaA_root_wiboxes(lua_State
*L
)
142 lua_createtable(L
, globalconf
.wiboxes
.len
, 0);
144 for(int i
= 0; i
< globalconf
.wiboxes
.len
; i
++)
146 wibox_push(L
, globalconf
.wiboxes
.tab
[i
]);
147 lua_rawseti(L
, -2, i
+ 1);
154 luaA_root_index(lua_State
*L
)
157 const char *attr
= luaL_checklstring(L
, 2, &len
);
159 switch(a_tokenize(attr
, len
))
162 return luaA_object_push(L
, globalconf
.keys
);
164 return luaA_object_push(L
, globalconf
.buttons
);
171 luaA_root_newindex(lua_State
*L
)
174 const char *attr
= luaL_checklstring(L
, 2, &len
);
176 switch(a_tokenize(attr
, len
))
179 luaA_object_unref(L
, globalconf
.keys
);
180 globalconf
.keys
= luaA_object_ref(L
, 3);
183 luaA_object_unref(L
, globalconf
.buttons
);
184 globalconf
.buttons
= luaA_object_ref(L
, 3);
193 const struct luaL_reg awesome_root_methods
[] =
195 { "cursor", luaA_root_cursor
},
196 { "fake_input", luaA_root_fake_input
},
197 { "wiboxes", luaA_root_wiboxes
},
198 { "__index", luaA_root_index
},
199 { "__newindex", luaA_root_newindex
},
203 const struct luaL_reg awesome_root_meta
[] =
208 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80