imagebox: remove valign
[awesome.git] / root.c
blobaf2ebb7078e7445a0bfeb83b1206e58aeedd6ae9
1 /*
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>
24 #include "structs.h"
25 #include "wibox.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.
33 * \luastack
34 * \lparam The event type: key_press, key_release, button_press, button_release
35 * or motion_notify.
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.
44 static int
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.");
50 return 0;
53 size_t tlen;
54 const char *stype = luaL_checklstring(L, 1, &tlen);
55 uint8_t type, detail;
56 int x = 0, y = 0;
57 xcb_window_t root = XCB_NONE;
59 switch(a_tokenize(stype, tlen))
61 case A_TK_KEY_PRESS:
62 type = XCB_KEY_PRESS;
63 detail = luaL_checknumber(L, 2); /* keycode */
64 break;
65 case A_TK_KEY_RELEASE:
66 type = XCB_KEY_RELEASE;
67 detail = luaL_checknumber(L, 2); /* keycode */
68 break;
69 case A_TK_BUTTON_PRESS:
70 type = XCB_BUTTON_PRESS;
71 detail = luaL_checknumber(L, 2); /* button number */
72 break;
73 case A_TK_BUTTON_RELEASE:
74 type = XCB_BUTTON_RELEASE;
75 detail = luaL_checknumber(L, 2); /* button number */
76 break;
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;
88 break;
89 default:
90 return 0;
93 xcb_test_fake_input(globalconf.connection,
94 type,
95 detail,
96 XCB_CURRENT_TIME,
97 root,
98 x, y,
99 0);
100 return 0;
103 /** Set the root cursor.
104 * \param L The Lua VM state.
105 * \return The number of element pushed on stack.
106 * \luastack
107 * \lparam A X cursor name.
109 static int
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);
115 if(cursor_font)
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));
121 screen_nbr++)
122 xcb_change_window_attributes(globalconf.connection,
123 xutil_screen_get(globalconf.connection, screen_nbr)->root,
124 XCB_CW_CURSOR,
125 change_win_vals);
127 else
128 luaA_warn(L, "invalid cursor %s", cursor_name);
130 return 0;
133 /** Get the wiboxes attached to a screen.
134 * \param L The Lua VM state.
135 * \return The number of element pushed on stack.
136 * \luastack
137 * \lreturn A table with all wiboxes.
139 static int
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);
150 return 1;
153 static int
154 luaA_root_index(lua_State *L)
156 size_t len;
157 const char *attr = luaL_checklstring(L, 2, &len);
159 switch(a_tokenize(attr, len))
161 case A_TK_KEYS:
162 return luaA_object_push(L, globalconf.keys);
163 case A_TK_BUTTONS:
164 return luaA_object_push(L, globalconf.buttons);
165 default:
166 return 0;
170 static int
171 luaA_root_newindex(lua_State *L)
173 size_t len;
174 const char *attr = luaL_checklstring(L, 2, &len);
176 switch(a_tokenize(attr, len))
178 case A_TK_KEYS:
179 luaA_object_unref(L, globalconf.keys);
180 globalconf.keys = luaA_object_ref(L, 3);
181 break;
182 case A_TK_BUTTONS:
183 luaA_object_unref(L, globalconf.buttons);
184 globalconf.buttons = luaA_object_ref(L, 3);
185 break;
186 default:
187 break;
190 return 0;
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 },
200 { NULL, NULL }
203 const struct luaL_reg awesome_root_meta[] =
205 { NULL, NULL }
208 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80