1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00

Move more to xcb, window_*_ functions to xcb_ functions

This commit is contained in:
Dave Davenport 2016-02-27 21:55:43 +01:00
parent a02cb83a98
commit bb2f0d8b83
5 changed files with 42 additions and 31 deletions

View file

@ -27,10 +27,7 @@ int window_get_prop ( Display *display, Window w, Atom prop,
*/
char* window_get_text_prop ( Display *display, Window w, Atom atom );
int window_get_atom_prop ( Display *display, Window w, Atom atom, Atom *list, int count );
void window_set_atom_prop ( xcb_connection_t *xcb_connection, Window w, xcb_atom_t prop, xcb_atom_t *atoms, int count );
int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list,
int count );
/**
* Window info.
@ -125,7 +122,7 @@ void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key );
*
* Set the opacity of the window and sub-windows.
*/
void x11_set_window_opacity ( Display *display, Window box, unsigned int opacity );
void x11_set_window_opacity ( xcb_connection_t *xcb_connection, Window box, unsigned int opacity );
/**
* Setup several items required.

View file

@ -35,6 +35,7 @@
#include <string.h>
#include <errno.h>
#include <xcb/xcb.h>
#include <xcb/xcb_ewmh.h>
#include <X11/X.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
@ -56,7 +57,10 @@
#define CLIENTWINDOWTYPE 10
#define CLIENTROLE 50
extern xcb_connection_t *xcb_connection;
extern xcb_ewmh_connection_t xcb_ewmh;
extern xcb_screen_t *xcb_screen;
extern int xcb_screen_nbr;
// a manageable window
typedef struct
{
@ -272,9 +276,17 @@ static client* window_client ( Display *display, Window win )
memmove ( &c->xattr, attr, sizeof ( XWindowAttributes ) );
XGetTransientForHint ( display, win, &c->trans );
c->states = window_get_atom_prop ( display, win, netatoms[_NET_WM_STATE], c->state, CLIENTSTATE );
c->window_types = window_get_atom_prop ( display, win, netatoms[_NET_WM_WINDOW_TYPE], c->window_type, CLIENTWINDOWTYPE );
xcb_get_property_cookie_t cky = xcb_ewmh_get_wm_state(&xcb_ewmh, win);
xcb_ewmh_get_atoms_reply_t states;
if(xcb_ewmh_get_wm_state_reply( &xcb_ewmh, cky, &states, NULL)){
c->states = MIN(CLIENTSTATE,states.atoms_len);
memcpy(c->state, states.atoms, MIN(CLIENTSTATE, states.atoms_len));
}
cky = xcb_ewmh_get_wm_window_type(&xcb_ewmh, win);
if(xcb_ewmh_get_wm_window_type_reply( &xcb_ewmh, cky, &states, NULL)){
c->window_types= MIN(CLIENTWINDOWTYPE,states.atoms_len);
memcpy(c->window_type, states.atoms, MIN(CLIENTWINDOWTYPE, states.atoms_len));
}
char *name;
if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) {
@ -399,8 +411,9 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
}
// Get the current desktop.
unsigned long current_desktop = 0;
if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_CURRENT_DESKTOP], &current_desktop, 1 ) ) {
unsigned int current_desktop = 0;
xcb_get_property_cookie_t c = xcb_ewmh_get_current_desktop( &xcb_ewmh, xcb_screen_nbr);
if ( !xcb_ewmh_get_current_desktop_reply ( &xcb_ewmh, c, &current_desktop, NULL )){
current_desktop = 0;
}
@ -418,7 +431,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
char pattern[50];
int i;
unsigned int classfield = 0;
unsigned long desktops = 0;
unsigned int desktops = 0;
// windows we actually display. May be slightly different to _NET_CLIENT_LIST_STACKING
// if we happen to have a window destroyed while we're working...
pd->ids = winlist_new ();
@ -450,9 +463,11 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
}
// Create pattern for printing the line.
if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_NUMBER_OF_DESKTOPS], &desktops, 1 ) ) {
xcb_get_property_cookie_t c = xcb_ewmh_get_number_of_desktops( &xcb_ewmh, xcb_screen_nbr);
if ( !xcb_ewmh_get_number_of_desktops_reply ( &xcb_ewmh, c, &desktops, NULL )){
desktops= 1;
}
if ( pd->config_i3_mode ) {
snprintf ( pattern, 50, "%%-%ds %%s", MAX ( 5, classfield ) );
}
@ -469,21 +484,31 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
if ( ( c = window_client ( display, w ) ) ) {
// final line format
unsigned long wmdesktop;
unsigned int wmdesktop;
char desktop[5];
desktop[0] = 0;
size_t len = strlen ( c->title ) + strlen ( c->class ) + classfield + 50;
char *line = g_malloc ( len );
if ( !pd->config_i3_mode ) {
// find client's desktop.
if ( !window_get_cardinal_prop ( display, c->window, netatoms[_NET_WM_DESKTOP], &wmdesktop, 1 ) ) {
xcb_get_property_cookie_t cookie;
xcb_get_property_reply_t *r;
cookie = xcb_get_property(xcb_connection, 0, c->window, xcb_ewmh._NET_WM_DESKTOP, XCB_GET_PROPERTY, 0, sizeof(unsigned int));
r = xcb_get_property_reply(xcb_connection, cookie, NULL);
if ( r->type == XCB_ATOM_INTEGER){
wmdesktop = *((int *)xcb_get_property_value(r));
}
if ( r->type != XCB_ATOM_INTEGER) {
// Assume the client is on all desktops.
wmdesktop = 0xFFFFFFFF;
}
else if ( cd && wmdesktop != current_desktop ) {
g_free ( line );
free(r);
continue;
}
free(r);
if ( wmdesktop < 0xFFFFFFFF ) {
snprintf ( desktop, 5, "%d", (int) wmdesktop );

View file

@ -150,7 +150,7 @@ void i3_support_free_internals ( void )
{
}
int i3_support_initialize ( Display *display )
int i3_support_initialize ( Display *display, xcb_connection_t *xcb_connection )
{
return FALSE;
}

View file

@ -559,7 +559,7 @@ static Window __create_window ( xcb_connection_t *xcb_connection, xcb_screen_t *
xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, box, xcb_ewmh._NET_WM_NAME, xcb_ewmh.UTF8_STRING, 8, 4,"rofi");
xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, box, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4,"rofi");
x11_set_window_opacity ( display, box, config.window_opacity );
x11_set_window_opacity ( xcb_connection, box, config.window_opacity );
return box;
}

View file

@ -147,23 +147,12 @@ char* window_get_text_prop ( Display *display, Window w, Atom atom )
return res;
}
int window_get_atom_prop ( Display *display, Window w, Atom atom, Atom *list, int count )
{
Atom type;
int items;
return window_get_prop ( display, w, atom, &type, &items, list, count * sizeof ( Atom ) ) && type == XA_ATOM ? items : 0;
}
void window_set_atom_prop ( xcb_connection_t *xcb_connection, Window w, xcb_atom_t prop, xcb_atom_t *atoms, int count )
{
xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, w, prop, XCB_ATOM_ATOM, 32, count, atoms);
}
int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list, int count )
{
Atom type; int items;
return window_get_prop ( display, w, atom, &type, &items, list, count * sizeof ( unsigned long ) ) && type == XA_CARDINAL ? items : 0;
}
extern xcb_screen_t *xcb_screen;
extern int xcb_screen_nbr;
int monitor_get_smallest_size ( xcb_connection_t *xcb_connection )
@ -534,13 +523,13 @@ void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key )
*key = sym;
}
void x11_set_window_opacity ( Display *display, Window box, unsigned int opacity )
void x11_set_window_opacity ( xcb_connection_t *xcb_connection, Window box, unsigned int opacity )
{
// Scale 0-100 to 0 - UINT32_MAX.
unsigned int opacity_set = ( unsigned int ) ( ( opacity / 100.0 ) * UINT32_MAX );
// Set opacity.
XChangeProperty ( display, box, netatoms[_NET_WM_WINDOW_OPACITY], XA_CARDINAL, 32, PropModeReplace,
( unsigned char * ) &opacity_set, 1L );
xcb_change_property( xcb_connection, XCB_PROP_MODE_REPLACE, box,
netatoms[_NET_WM_WINDOW_OPACITY], XCB_ATOM_CARDINAL, 32, 1L, &opacity_set);
}
/**