Replace xcb_aux_get_screen() by a safer function

This commit is contained in:
Arnaud Fontaine 2008-06-17 23:55:24 +09:00 committed by Julien Danjou
parent 6d2fc20038
commit b9e1ec69d0
18 changed files with 60 additions and 42 deletions

View File

@ -79,7 +79,7 @@ scan(void)
for(screen = 0; screen < screen_max; screen++)
{
/* Get the root window ID associated to this screen */
root_wins[screen].id = xcb_aux_get_screen(globalconf.connection, screen)->root;
root_wins[screen].id = xutil_screen_get(globalconf.connection, screen)->root;
/* Get the window tree associated to this screen */
root_wins[screen].tree_cookie = xcb_query_tree_unchecked(globalconf.connection,
@ -384,7 +384,7 @@ main(int argc, char **argv)
/* This causes an error if some other window manager is running */
xcb_change_window_attributes(globalconf.connection,
xcb_aux_get_screen(globalconf.connection, screen_nbr)->root,
xutil_screen_get(globalconf.connection, screen_nbr)->root,
XCB_CW_EVENT_MASK, &select_input_val);
}
@ -459,7 +459,7 @@ main(int argc, char **argv)
};
xcb_change_window_attributes(globalconf.connection,
xcb_aux_get_screen(globalconf.connection, screen_nbr)->root,
xutil_screen_get(globalconf.connection, screen_nbr)->root,
XCB_CW_EVENT_MASK | XCB_CW_CURSOR,
change_win_vals);
ewmh_set_supported_hints(screen_nbr);

View File

@ -263,7 +263,7 @@ client_focus(client_t *c, int screen)
phys_screen = screen_virttophys(screen);
xcb_set_input_focus(globalconf.connection,
XCB_INPUT_FOCUS_POINTER_ROOT,
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
xutil_screen_get(globalconf.connection, phys_screen)->root,
XCB_CURRENT_TIME);
}

View File

@ -44,6 +44,7 @@
#include "common/draw.h"
#include "common/markup.h"
#include "common/xutil.h"
/** Convert text from any charset to UTF-8 using iconv
* \param iso the ISO string to convert
@ -124,7 +125,7 @@ draw_context_new(xcb_connection_t *conn, int phys_screen,
xcolor_t fg, xcolor_t bg)
{
draw_context_t *d = p_new(draw_context_t, 1);
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
xcb_screen_t *s = xutil_screen_get(conn, phys_screen);
d->connection = conn;
d->phys_screen = phys_screen;
@ -152,7 +153,7 @@ font_t *
draw_font_new(xcb_connection_t *conn, int phys_screen, const char *fontname)
{
cairo_surface_t *surface;
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
xcb_screen_t *s = xutil_screen_get(conn, phys_screen);
cairo_t *cr;
PangoLayout *layout;
font_t *font = p_new(font_t, 1);
@ -980,7 +981,7 @@ draw_text_extents(xcb_connection_t *conn, int phys_screen, font_t *font, const c
cairo_t *cr;
PangoLayout *layout;
PangoRectangle ext;
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
xcb_screen_t *s = xutil_screen_get(conn, phys_screen);
area_t geom = { 0, 0, 0, 0, NULL, NULL };
ssize_t len;
char *buf, *utf8;
@ -1060,7 +1061,7 @@ draw_align_get_from_str(const char *align)
bool
xcolor_new(xcb_connection_t *conn, int phys_screen, const char *colstr, xcolor_t *color)
{
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
xcb_screen_t *s = xutil_screen_get(conn, phys_screen);
xcb_alloc_color_reply_t *hexa_color = NULL;
xcb_alloc_named_color_reply_t *named_color = NULL;
unsigned long colnum;

View File

@ -23,6 +23,7 @@
#include <xcb/xcb_aux.h>
#include "common/swindow.h"
#include "common/xutil.h"
/** Create a simple window.
* \param conn Connection ref.
@ -41,7 +42,7 @@ simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y,
unsigned int border_width)
{
simple_window_t *sw;
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
xcb_screen_t *s = xutil_screen_get(conn, phys_screen);
uint32_t create_win_val[3];
const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel };
@ -106,7 +107,7 @@ simplewindow_move(simple_window_t *sw, int x, int y)
void
simplewindow_resize(simple_window_t *sw, unsigned int w, unsigned int h)
{
xcb_screen_t *s = xcb_aux_get_screen(sw->connection, sw->phys_screen);
xcb_screen_t *s = xutil_screen_get(sw->connection, sw->phys_screen);
const uint32_t resize_win_vals[] = { w, h };
xcb_pixmap_t d;
@ -134,7 +135,7 @@ simplewindow_moveresize(simple_window_t *sw, int x, int y,
{
const uint32_t moveresize_win_vals[] = { x, y, w, h };
xcb_pixmap_t d;
xcb_screen_t *s = xcb_aux_get_screen(sw->connection, sw->phys_screen);
xcb_screen_t *s = xutil_screen_get(sw->connection, sw->phys_screen);
sw->geometry.x = x;
sw->geometry.y = y;

View File

@ -24,6 +24,7 @@
#include <xcb/xinerama.h>
#include "common/xscreen.h"
#include "common/xutil.h"
/** Return the Xinerama screen number where the coordinates belongs to.
* \param si The screens infos structure.
@ -144,7 +145,7 @@ screensinfo_new(xcb_connection_t *conn)
si->geometry = p_new(area_t, si->nscreen);
for(screen = 0; screen < si->nscreen; screen++)
{
s = xcb_aux_get_screen(conn, screen);
s = xutil_screen_get(conn, screen);
si->geometry[screen].x = 0;
si->geometry[screen].y = 0;
si->geometry[screen].width = s->width_in_pixels;

View File

@ -26,6 +26,7 @@
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
#include <xcb/xcb_aux.h>
#include <xcb/xcb_event.h>
/* XCB doesn't provide keysyms definition */
@ -160,5 +161,19 @@ xcb_keysym_t xutil_keymask_fromstr(const char *);
unsigned int xutil_button_fromint(int);
xcb_cursor_t xutil_cursor_new(xcb_connection_t *, unsigned int);
/* 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)
{
if(xcb_connection_has_error(c))
eprint("X connection invalid");
return xcb_aux_get_screen(c, screen);
}
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

10
event.c
View File

@ -163,7 +163,7 @@ event_handle_buttonpress(void *data __attribute__ ((unused)),
}
else
for(screen = 0; screen < nb_screen; screen++)
if(xcb_aux_get_screen(connection, screen)->root == ev->event)
if(xutil_screen_get(connection, screen)->root == ev->event)
{
event_handle_mouse_button_press(NULL, ev->detail, ev->state,
globalconf.buttons.root);
@ -279,7 +279,7 @@ event_handle_configurenotify(void *data __attribute__ ((unused)),
const xcb_screen_t *screen;
for(screen_nbr = 0; screen_nbr < xcb_setup_roots_length(xcb_get_setup (connection)); screen_nbr++)
if((screen = xcb_aux_get_screen(connection, screen_nbr)) != NULL
if((screen = xutil_screen_get(connection, screen_nbr)) != NULL
&& ev->window == screen->root
&& (ev->width != screen->width_in_pixels
|| ev->height != screen->height_in_pixels))
@ -340,7 +340,7 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
}
else if((emwin = xembed_getbywin(globalconf.embedded, ev->event)))
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY,
xcb_aux_get_screen(connection, emwin->phys_screen)->root,
xutil_screen_get(connection, emwin->phys_screen)->root,
ANY_MODIFIER);
else
window_root_grabbuttons(ev->root);
@ -458,7 +458,7 @@ event_handle_maprequest(void *data __attribute__ ((unused)),
geom_c = xcb_get_geometry(connection, ev->window);
if(globalconf.screens_info->xinerama_is_active)
qp_c = xcb_query_pointer(connection, xcb_aux_get_screen(globalconf.connection,
qp_c = xcb_query_pointer(connection, xutil_screen_get(globalconf.connection,
screen_nbr)->root);
if(!(geom_r = xcb_get_geometry_reply(connection, geom_c, NULL)))
@ -552,7 +552,7 @@ event_handle_unmapnotify(void *data __attribute__ ((unused)),
bool send_event = ((ev->response_type & 0x80) >> 7);
if((c = client_getbywin(ev->window))
&& ev->event == xcb_aux_get_screen(connection, c->phys_screen)->root
&& ev->event == xutil_screen_get(connection, c->phys_screen)->root
&& send_event && window_getstate(c->win) == XCB_WM_NORMAL_STATE)
client_unmanage(c);

14
ewmh.c
View File

@ -163,7 +163,7 @@ ewmh_set_supported_hints(int phys_screen)
atom[i++] = net_wm_state_hidden;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
xutil_screen_get(globalconf.connection, phys_screen)->root,
net_supported, ATOM, 32, i, atom);
}
@ -184,7 +184,7 @@ ewmh_update_net_client_list(int phys_screen)
wins[n] = c->win;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
xutil_screen_get(globalconf.connection, phys_screen)->root,
net_client_list, WINDOW, 32, n, wins);
p_delete(&wins);
@ -200,7 +200,7 @@ ewmh_update_net_numbers_of_desktop(int phys_screen)
count++;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
xutil_screen_get(globalconf.connection, phys_screen)->root,
net_number_of_desktops, CARDINAL, 32, 1, &count);
}
@ -214,7 +214,7 @@ ewmh_update_net_current_desktop(int phys_screen)
count++;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
xutil_screen_get(globalconf.connection, phys_screen)->root,
net_current_desktop, CARDINAL, 32, 1, &count);
p_delete(&curtags);
@ -238,7 +238,7 @@ ewmh_update_net_desktop_names(int phys_screen)
}
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
xutil_screen_get(globalconf.connection, phys_screen)->root,
net_desktop_names, utf8_string, 8, len, buf);
}
@ -251,7 +251,7 @@ ewmh_update_net_active_window(int phys_screen)
win = sel ? sel->win : XCB_NONE;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
xutil_screen_get(globalconf.connection, phys_screen)->root,
net_active_window, WINDOW, 32, 1, &win);
}
@ -392,7 +392,7 @@ ewmh_process_client_message(xcb_client_message_event_t *ev)
screen < xcb_setup_roots_length(xcb_get_setup(globalconf.connection));
screen++)
{
if(ev->window == xcb_aux_get_screen(globalconf.connection, screen)->root)
if(ev->window == xutil_screen_get(globalconf.connection, screen)->root)
tag_view_only_byindex(screen, ev->data.data32[0]);
}

View File

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

View File

@ -59,7 +59,7 @@ arrange(int screen)
}
qp_c = xcb_query_pointer_unchecked(globalconf.connection,
xcb_aux_get_screen(globalconf.connection,
xutil_screen_get(globalconf.connection,
phys_screen)->root);
/* check that the mouse is on a window or not */

16
mouse.c
View File

@ -419,7 +419,7 @@ mouse_get_client_under_pointer(void)
xcb_query_pointer_reply_t *query_ptr_r;
client_t *c = NULL;
root = xcb_aux_get_screen(globalconf.connection, globalconf.default_screen)->root;
root = xutil_screen_get(globalconf.connection, globalconf.default_screen)->root;
query_ptr_c = xcb_query_pointer_unchecked(globalconf.connection, root);
query_ptr_r = xcb_query_pointer_reply(globalconf.connection, query_ptr_c, NULL);
@ -454,7 +454,7 @@ mouse_client_move(client_t *c, int snap, bool infobox)
xcb_window_t root;
layout = layout_get_current(c->screen);
root = xcb_aux_get_screen(globalconf.connection, c->phys_screen)->root;
root = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
/* get current pointer position */
mouse_query_pointer(root, &last_x, &last_y);
@ -561,7 +561,7 @@ mouse_client_resize_floating(client_t *c, corner_t corner, bool infobox)
size_t cursor = CurResize;
int top, bottom, left, right;
screen = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
screen = xutil_screen_get(globalconf.connection, c->phys_screen);
/* get current mouse position */
mouse_query_pointer(screen->root, &mouse_x, &mouse_y);
@ -656,7 +656,7 @@ mouse_client_resize_tiled(client_t *c)
int mouse_x, mouse_y;
size_t cursor = CurResize;
screen = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
screen = xutil_screen_get(globalconf.connection, c->phys_screen);
tag = tags_get_current(c->screen)[0];
layout = tag->layout;
@ -763,7 +763,7 @@ mouse_client_resize_magnified(client_t *c, bool infobox)
tag = tags_get_current(c->screen)[0];
root = xcb_aux_get_screen(globalconf.connection, c->phys_screen)->root;
root = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
area = screen_area_get(tag->screen,
globalconf.screens[tag->screen].statusbar,
@ -868,7 +868,7 @@ mouse_client_resize(client_t *c, corner_t corner, bool infobox)
curtags = tags_get_current(c->screen);
layout = curtags[0]->layout;
s = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
s = xutil_screen_get(globalconf.connection, c->phys_screen);
/* only handle floating, tiled and magnifier layouts */
if(layout == layout_floating || c->isfloating)
@ -919,7 +919,7 @@ luaA_mouse_coords_set(lua_State *L)
x = luaL_checknumber(L, 1);
y = luaL_checknumber(L, 2);
root = xcb_aux_get_screen(globalconf.connection, globalconf.default_screen)->root;
root = xutil_screen_get(globalconf.connection, globalconf.default_screen)->root;
mouse_warp_pointer(root, x, y);
return 0;
@ -994,7 +994,7 @@ luaA_mouse_screen_get(lua_State *L)
int screen, mouse_x, mouse_y;
xcb_window_t root;
root = xcb_aux_get_screen(globalconf.connection, globalconf.default_screen)->root;
root = xutil_screen_get(globalconf.connection, globalconf.default_screen)->root;
if(!mouse_query_pointer(root, &mouse_x, &mouse_y))
return 0;

View File

@ -135,7 +135,7 @@ placement_under_mouse(client_t *c)
area_t finalgeometry = c->f_geometry;
qp_c = xcb_query_pointer(globalconf.connection,
xcb_aux_get_screen(globalconf.connection, c->phys_screen)->root);
xutil_screen_get(globalconf.connection, c->phys_screen)->root);
if((qp_r = xcb_query_pointer_reply(globalconf.connection, qp_c, NULL)))
{
finalgeometry.x = qp_r->root_x - c->f_geometry.width / 2;

View File

@ -84,7 +84,7 @@ display_area_get(int phys_screen, statusbar_t *statusbar, padding_t *padding)
{
area_t area = { 0, 0, 0, 0, NULL, NULL };
statusbar_t *sb;
xcb_screen_t *s = xcb_aux_get_screen(globalconf.connection, phys_screen);
xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
area.width = s->width_in_pixels;
area.height = s->height_in_pixels;

View File

@ -167,7 +167,7 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
statusbar->sw =
simplewindow_new(globalconf.connection, statusbar->phys_screen, 0, 0,
statusbar->height, statusbar->width, 0);
s = xcb_aux_get_screen(globalconf.connection, statusbar->phys_screen);
s = xutil_screen_get(globalconf.connection, statusbar->phys_screen);
/* we need a new pixmap this way [ ] to render */
dw = xcb_generate_id(globalconf.connection);
xcb_create_pixmap(globalconf.connection,

View File

@ -40,7 +40,7 @@ systray_init(int phys_screen)
xutil_intern_atom_request_t atom_systray_q, atom_manager_q;
xcb_atom_t atom_systray;
xcb_client_message_event_t ev;
xcb_screen_t *xscreen = xcb_aux_get_screen(globalconf.connection, phys_screen);
xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen);
char atom_name[22];
/* Send requests */

View File

@ -77,7 +77,7 @@ titlebar_draw(client_t *c)
if(!c->titlebar || !c->titlebar->sw || !c->titlebar->position)
return;
s = xcb_aux_get_screen(globalconf.connection,
s = xutil_screen_get(globalconf.connection,
c->titlebar->sw->phys_screen);
switch(c->titlebar->position)

View File

@ -154,7 +154,7 @@ widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_
if(ctx->bg.alpha != 0xffff)
{
s = xcb_aux_get_screen(globalconf.connection, ctx->phys_screen);
s = xutil_screen_get(globalconf.connection, ctx->phys_screen);
pixmap_atom = xutil_intern_atom_reply(globalconf.connection, &globalconf.atoms, pixmap_atom_req);
rootpix_atom = xutil_intern_atom_reply(globalconf.connection, &globalconf.atoms, rootpix_atom_req);
prop_c = xcb_get_property_unchecked(globalconf.connection, false, s->root, rootpix_atom,

View File

@ -172,7 +172,7 @@ window_root_grabkey(keybinding_t *k)
|| (k->keysym && (kc = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym))))
do
{
s = xcb_aux_get_screen(globalconf.connection, phys_screen);
s = xutil_screen_get(globalconf.connection, phys_screen);
xcb_grab_key(globalconf.connection, true, s->root,
k->mod, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
xcb_grab_key(globalconf.connection, true, s->root,
@ -201,7 +201,7 @@ window_root_ungrabkey(keybinding_t *k)
|| (k->keysym && (kc = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym))))
do
{
s = xcb_aux_get_screen(globalconf.connection, phys_screen);
s = xutil_screen_get(globalconf.connection, phys_screen);
xcb_ungrab_key(globalconf.connection, kc, s->root,
k->mod);
xcb_ungrab_key(globalconf.connection, kc, s->root,