Save the screen in globalconf.

There can only be on xcb_screen_t now, so we can save it in globalconf.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-08-16 14:10:58 +02:00
parent cc4e8d57d5
commit 5d35771673
17 changed files with 49 additions and 80 deletions

View File

@ -97,7 +97,7 @@ scan(void)
long state;
/* Get the root window ID associated to this screen */
root_win.id = xutil_screen_get(globalconf.connection, globalconf.default_screen)->root;
root_win.id = globalconf.screen->root;
/* Get the window tree associated to this screen */
root_win.tree_cookie = xcb_query_tree_unchecked(globalconf.connection,
@ -368,6 +368,8 @@ main(int argc, char **argv)
if(xcb_connection_has_error(globalconf.connection))
fatal("cannot open display");
globalconf.screen = xcb_aux_get_screen(globalconf.connection, globalconf.default_screen);
/* Prefetch all the extensions we might need */
xcb_prefetch_extension_data(globalconf.connection, &xcb_big_requests_id);
xcb_prefetch_extension_data(globalconf.connection, &xcb_test_id);
@ -398,7 +400,7 @@ main(int argc, char **argv)
/* This causes an error if some other window manager is running */
xcb_change_window_attributes(globalconf.connection,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
XCB_CW_EVENT_MASK, &select_input_val);
}
@ -478,7 +480,7 @@ main(int argc, char **argv)
};
xcb_change_window_attributes(globalconf.connection,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
XCB_CW_EVENT_MASK,
change_win_vals);
}

View File

@ -87,7 +87,6 @@ color_parse(const char *colstr, ssize_t len,
color_init_cookie_t
color_init_unchecked(color_t *color, const char *colstr, ssize_t len)
{
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
color_init_cookie_t req;
p_clear(&req, 1);
@ -117,7 +116,8 @@ color_init_unchecked(color_t *color, const char *colstr, ssize_t len)
req.color = color;
req.colstr = colstr;
req.cookie = xcb_alloc_named_color_unchecked(globalconf.connection,
s->default_colormap, len,
globalconf.screen->default_colormap,
len,
colstr);
}
@ -168,7 +168,6 @@ color_init_reply(color_init_cookie_t req)
xcolor_init_request_t
xcolor_init_unchecked(xcolor_t *color, const char *colstr, ssize_t len)
{
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcolor_init_request_t req;
uint8_t red, green, blue, alpha;
@ -197,7 +196,7 @@ xcolor_init_unchecked(xcolor_t *color, const char *colstr, ssize_t len)
req.is_hexa = true;
req.cookie_hexa = xcb_alloc_color_unchecked(globalconf.connection,
s->default_colormap,
globalconf.screen->default_colormap,
RGB_8TO16(red),
RGB_8TO16(green),
RGB_8TO16(blue));
@ -206,7 +205,7 @@ xcolor_init_unchecked(xcolor_t *color, const char *colstr, ssize_t len)
{
req.is_hexa = false;
req.cookie_named = xcb_alloc_named_color_unchecked(globalconf.connection,
s->default_colormap, len,
globalconf.screen->default_colormap, len,
colstr);
}

View File

@ -60,25 +60,5 @@ void xutil_lock_mask_get(xcb_connection_t *, xcb_get_modifier_mapping_cookie_t,
uint16_t xutil_key_mask_fromstr(const char *, size_t);
void xutil_key_mask_tostr(uint16_t, const char **, size_t *);
/* Get the informations about the screen.
* \param c X connection.
* \param screen Screen number.
* \return Screen informations (must not be freed!).
*/
static inline xcb_screen_t *
xutil_screen_get(xcb_connection_t *c, int screen)
{
xcb_screen_t *s;
if(xcb_connection_has_error(c))
fatal("X connection invalid");
s = xcb_aux_get_screen(c, screen);
assert(s);
return s;
}
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

5
draw.c
View File

@ -336,7 +336,6 @@ draw_text_extents(draw_text_context_t *data)
cairo_t *cr;
PangoLayout *layout;
PangoRectangle ext;
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
area_t geom = { 0, 0, 0, 0 };
if(data->len <= 0)
@ -345,8 +344,8 @@ draw_text_extents(draw_text_context_t *data)
surface = cairo_xcb_surface_create(globalconf.connection,
globalconf.default_screen,
globalconf.visual,
s->width_in_pixels,
s->height_in_pixels);
globalconf.screen->width_in_pixels,
globalconf.screen->height_in_pixels);
cr = cairo_create(surface);
layout = pango_cairo_create_layout(cr);

View File

@ -192,7 +192,7 @@ event_handle_button(xcb_button_press_event_t *ev)
XCB_CURRENT_TIME);
}
else if(ev->child == XCB_NONE)
if(xutil_screen_get(globalconf.connection, globalconf.default_screen)->root == ev->event)
if(globalconf.screen->root == ev->event)
{
event_button_callback(ev, &globalconf.buttons, 0, 0, NULL);
return;
@ -287,7 +287,7 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev)
static void
event_handle_configurenotify(xcb_configure_notify_event_t *ev)
{
const xcb_screen_t *screen = xutil_screen_get(globalconf.connection, globalconf.default_screen);
const xcb_screen_t *screen = globalconf.screen;
if(ev->window == screen->root
&& (ev->width != screen->width_in_pixels
@ -721,7 +721,7 @@ event_handle_mappingnotify(xcb_mapping_notify_event_t *ev)
&globalconf.modeswitchmask);
/* regrab everything */
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *s = globalconf.screen;
/* yes XCB_BUTTON_MASK_ANY is also for grab_key even if it's look weird */
xcb_ungrab_key(globalconf.connection, XCB_GRAB_ANY, s->root, XCB_BUTTON_MASK_ANY);
xwindow_grabkeys(s->root, &globalconf.keys);
@ -744,8 +744,7 @@ event_handle_reparentnotify(xcb_reparent_notify_event_t *ev)
{
/* Ignore reparents to the root window, they *might* be caused by
* ourselves if a client quickly unmaps and maps itself again. */
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
if (ev->parent != s->root)
if (ev->parent != globalconf.screen->root)
client_unmanage(c);
}
}

16
ewmh.c
View File

@ -106,7 +106,7 @@ ewmh_update_desktop_geometry(void)
uint32_t sizes[] = { geom.width, geom.height };
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
_NET_DESKTOP_GEOMETRY, XCB_ATOM_CARDINAL, 32, countof(sizes), sizes);
}
@ -121,7 +121,7 @@ ewmh_update_net_active_window(lua_State *L)
win = XCB_NONE;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
_NET_ACTIVE_WINDOW, XCB_ATOM_WINDOW, 32, 1, &win);
return 0;
@ -131,7 +131,7 @@ void
ewmh_init(void)
{
xcb_window_t father;
xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *xscreen = globalconf.screen;
xcb_atom_t atom[] =
{
_NET_SUPPORTED,
@ -231,7 +231,7 @@ ewmh_update_net_client_list(void)
}
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
_NET_CLIENT_LIST, XCB_ATOM_WINDOW, 32, n, wins);
}
@ -247,7 +247,7 @@ ewmh_update_net_client_list_stacking(void)
wins[n++] = (*client)->window;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
_NET_CLIENT_LIST_STACKING, XCB_ATOM_WINDOW, 32, n, wins);
}
@ -257,7 +257,7 @@ ewmh_update_net_numbers_of_desktop(void)
uint32_t count = globalconf.screens.tab[0].tags.len;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
_NET_NUMBER_OF_DESKTOPS, XCB_ATOM_CARDINAL, 32, 1, &count);
}
@ -267,7 +267,7 @@ ewmh_update_net_current_desktop(void)
uint32_t idx = tags_get_first_selected_index(&globalconf.screens.tab[0]);
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
_NET_CURRENT_DESKTOP, XCB_ATOM_CARDINAL, 32, 1, &idx);
}
@ -285,7 +285,7 @@ ewmh_update_net_desktop_names(void)
}
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
_NET_DESKTOP_NAMES, UTF8_STRING, 8, buf.len, buf.s);
buffer_wipe(&buf);
}

View File

@ -111,6 +111,8 @@ typedef struct
SnMonitorContext *snmonitor;
/** The default visual, used to draw */
xcb_visualtype_t *visual;
/** The screen's information */
xcb_screen_t *screen;
} awesome_t;
extern awesome_t globalconf;

View File

@ -41,8 +41,7 @@ keygrabber_grab(void)
{
if((xgb = xcb_grab_keyboard_reply(globalconf.connection,
xcb_grab_keyboard(globalconf.connection, true,
xutil_screen_get(globalconf.connection,
globalconf.default_screen)->root,
globalconf.screen->root,
XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC,
XCB_GRAB_MODE_ASYNC),
NULL)))

14
mouse.c
View File

@ -71,7 +71,7 @@ mouse_query_pointer(xcb_window_t window, int16_t *x, int16_t *y, xcb_window_t *c
static bool
mouse_query_pointer_root(screen_t **s, int16_t *x, int16_t *y, xcb_window_t *child, uint16_t *mask)
{
xcb_window_t root = xutil_screen_get(globalconf.connection, globalconf.default_screen)->root;
xcb_window_t root = globalconf.screen->root;
if(mouse_query_pointer(root, x, y, child, mask))
{
@ -135,7 +135,6 @@ luaA_mouse_newindex(lua_State *L)
size_t len;
const char *attr = luaL_checklstring(L, 2, &len);
int x, y = 0;
xcb_window_t root;
int screen;
switch(a_tokenize(attr, len))
@ -144,12 +143,10 @@ luaA_mouse_newindex(lua_State *L)
screen = luaL_checknumber(L, 3) - 1;
luaA_checkscreen(screen);
root = xutil_screen_get(globalconf.connection, globalconf.default_screen)->root;
x = globalconf.screens.tab[screen].geometry.x;
y = globalconf.screens.tab[screen].geometry.y;
mouse_warp_pointer(root, x, y);
mouse_warp_pointer(globalconf.screen->root, x, y);
break;
default:
return 0;
@ -203,8 +200,6 @@ luaA_mouse_coords(lua_State *L)
if(lua_gettop(L) >= 1)
{
xcb_window_t root;
luaA_checktable(L, 1);
bool ignore_enter_notify = (lua_gettop(L) == 2 && luaA_checkboolean(L, 2));
@ -214,13 +209,10 @@ luaA_mouse_coords(lua_State *L)
x = luaA_getopt_number(L, 1, "x", mouse_x);
y = luaA_getopt_number(L, 1, "y", mouse_y);
root = xutil_screen_get(globalconf.connection,
screen_array_indexof(&globalconf.screens, screen))->root;
if(ignore_enter_notify)
client_ignore_enterleave_events();
mouse_warp_pointer(root, x, y);
mouse_warp_pointer(globalconf.screen->root, x, y);
if(ignore_enter_notify)
client_restore_enterleave_events();

View File

@ -35,7 +35,7 @@
static bool
mousegrabber_grab(xcb_cursor_t cursor)
{
xcb_window_t root = xutil_screen_get(globalconf.connection, globalconf.default_screen)->root;
xcb_window_t root = globalconf.screen->root;
for(int i = 1000; i; i--)
{

View File

@ -266,7 +266,7 @@ void
client_unfocus(client_t *c)
{
xcb_window_t root_win = xutil_screen_get(globalconf.connection, globalconf.default_screen)->root;
xcb_window_t root_win = globalconf.screen->root;
/* Set focus on root window, so no events leak to the current window.
* This kind of inlines client_set_focus(), but a root window will never have
* the WM_TAKE_FOCUS protocol.
@ -491,7 +491,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, bool startup)
xcb_change_save_set(globalconf.connection, XCB_SET_MODE_INSERT, w);
client_t *c = client_new(globalconf.L);
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *s = globalconf.screen;
/* consider the window banned */
c->isbanned = true;
@ -1076,9 +1076,8 @@ client_unmanage(client_t *c)
XCB_CW_EVENT_MASK,
(const uint32_t []) { 0 });
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_unmap_window(globalconf.connection, c->window);
xcb_reparent_window(globalconf.connection, c->window, s->root,
xcb_reparent_window(globalconf.connection, c->window, globalconf.screen->root,
c->geometry.x, c->geometry.y);
xcb_destroy_window(globalconf.connection, c->frame_window);

View File

@ -38,7 +38,7 @@ LUA_OBJECT_FUNCS(wibox_class, wibox_t, wibox)
static void
wibox_systray_kickout(void)
{
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *s = globalconf.screen;
if(globalconf.systray.parent != s->root)
{
@ -214,7 +214,7 @@ wibox_draw_context_update(wibox_t *w, xcb_screen_t *s)
static void
wibox_init(wibox_t *w)
{
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *s = globalconf.screen;
w->window = xcb_generate_id(globalconf.connection);
xcb_create_window(globalconf.connection, s->root_depth, w->window, s->root,
@ -306,7 +306,7 @@ wibox_moveresize(lua_State *L, int udx, area_t geometry)
if(w->pixmap != w->ctx.pixmap)
xcb_free_pixmap(globalconf.connection, w->ctx.pixmap);
w->pixmap = xcb_generate_id(globalconf.connection);
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *s = globalconf.screen;
xcb_create_pixmap(globalconf.connection, s->root_depth, w->pixmap, s->root,
w->geometry.width, w->geometry.height);
wibox_draw_context_update(w, s);
@ -378,7 +378,7 @@ wibox_set_orientation(lua_State *L, int udx, orientation_t o)
wibox_t *w = luaA_checkudata(L, udx, &wibox_class);
if(o != w->orientation)
{
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *s = globalconf.screen;
w->orientation = o;
/* orientation != East */
if(w->pixmap != w->ctx.pixmap)

View File

@ -251,7 +251,7 @@ widget_render(wibox_t *wibox)
char *data;
xcb_pixmap_t rootpix;
xcb_get_property_cookie_t prop_c;
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *s = globalconf.screen;
prop_c = xcb_get_property_unchecked(globalconf.connection, false, s->root, _XROOTPMAP_ID,
XCB_ATOM_PIXMAP, 0, 1);
if((prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL)))

6
root.c
View File

@ -86,7 +86,7 @@ luaA_root_fake_input(lua_State *L)
{
int screen = luaL_checknumber(L, 5) - 1;
luaA_checkscreen(screen);
root = xutil_screen_get(globalconf.connection, screen)->root;
root = globalconf.screen->root;
}
break;
default:
@ -128,7 +128,7 @@ luaA_root_keys(lua_State *L)
while(lua_next(L, 1))
key_array_append(&globalconf.keys, luaA_object_ref_class(L, -1, &key_class));
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *s = globalconf.screen;
xcb_ungrab_key(globalconf.connection, XCB_GRAB_ANY, s->root, XCB_BUTTON_MASK_ANY);
xwindow_grabkeys(s->root, &globalconf.keys);
@ -200,7 +200,7 @@ luaA_root_cursor(lua_State *L)
uint32_t change_win_vals[] = { xcursor_new(globalconf.connection, cursor_font) };
xcb_change_window_attributes(globalconf.connection,
xutil_screen_get(globalconf.connection, globalconf.default_screen)->root,
globalconf.screen->root,
XCB_CW_CURSOR,
change_win_vals);
}

View File

@ -86,9 +86,7 @@ screen_scan_randr(void)
/* A quick XRandR recall:
* You have CRTC that manages a part of a SCREEN.
* Each CRTC can draw stuff on one or more OUTPUT. */
xcb_screen_t *screen = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_randr_get_screen_resources_cookie_t screen_res_c = xcb_randr_get_screen_resources(globalconf.connection, screen->root);
xcb_randr_get_screen_resources_cookie_t screen_res_c = xcb_randr_get_screen_resources(globalconf.connection, globalconf.screen->root);
xcb_randr_get_screen_resources_reply_t *screen_res_r = xcb_randr_get_screen_resources_reply(globalconf.connection, screen_res_c, NULL);
/* Only use the data from XRandR if there is more than one screen
@ -220,7 +218,7 @@ screen_scan_xinerama(void)
static void screen_scan_x11(void)
{
/* One screen only / Zaphod mode */
xcb_screen_t *xcb_screen = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *xcb_screen = globalconf.screen;
screen_t s;
p_clear(&s, 1);
s.geometry.x = 0;
@ -239,7 +237,7 @@ screen_scan(void)
screen_scan_x11();
globalconf.screen_focus = globalconf.screens.tab;
globalconf.visual = screen_default_visual(xutil_screen_get(globalconf.connection, globalconf.default_screen));
globalconf.visual = screen_default_visual(globalconf.screen);
}
/** Return the Xinerama screen number where the coordinates belongs to.
@ -334,7 +332,7 @@ screen_area_get(screen_t *screen, bool strut)
area_t
display_area_get(void)
{
xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *s = globalconf.screen;
area_t area = { .x = 0,
.y = 0,
.width = s->width_in_pixels,

View File

@ -40,7 +40,7 @@ luaA_selection_get(lua_State *L)
{
if(selection_window == XCB_NONE)
{
xcb_screen_t *screen = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *screen = globalconf.screen;
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
uint32_t values[] = { screen->black_pixel, 1, XCB_EVENT_MASK_PROPERTY_CHANGE };

View File

@ -39,7 +39,7 @@
void
systray_init(void)
{
xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *xscreen = globalconf.screen;
globalconf.systray.window = xcb_generate_id(globalconf.connection);
xcb_create_window(globalconf.connection, xscreen->root_depth,
@ -74,7 +74,7 @@ void
systray_register(void)
{
xcb_client_message_event_t ev;
xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, globalconf.default_screen);
xcb_screen_t *xscreen = globalconf.screen;
char *atom_name;
xcb_intern_atom_cookie_t atom_systray_q;
xcb_intern_atom_reply_t *atom_systray_r;
@ -235,7 +235,7 @@ systray_process_client_message(xcb_client_message_event_t *ev)
if(!(geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL)))
return -1;
if(xutil_screen_get(globalconf.connection, globalconf.default_screen)->root == geom_r->root)
if(globalconf.screen->root == geom_r->root)
ret = systray_request_handle(ev->data.data32[2], NULL);
p_delete(&geom_r);