Skip to content

Commit

Permalink
Some switch from hardcoded to the ones in xcb_ewmh.h
Browse files Browse the repository at this point in the history
Lots of ewmh hints that were used were already present in the ewmh
holding structure, which we already had in the code, so why not use it
instead of having our own definition of it.
  • Loading branch information
venam committed Aug 8, 2016
1 parent 75419a6 commit 9efb565
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 41 deletions.
67 changes: 30 additions & 37 deletions 2bwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,8 @@ static struct item *monlist = NULL; // List of all physical monitor outpu
static struct item *wslist[WORKSPACES];
///---Global configuration.---///
static const char *atomnames[NB_ATOMS][1] = {
{"_NET_WM_DESKTOP"},
{"_NET_CURRENT_DESKTOP"},
{"_NET_UNKILLABLE"},
{"WM_DELETE_WINDOW"},
{"WM_CHANGE_STATE"},
{"WM_STATE"},
{"WM_PROTOCOLS"},
{"_NET_NUMBER_OF_DESKTOPS"},
{"_NET_ACTIVE_WINDOW"},
{"_NET_CLIENT_LIST"},
{"_NET_CLIENT_LIST_STACKING"},
{"_NET_WM_STATE_HIDDEN"}
{"WM_CHANGE_STATE"}
};

xcb_atom_t ATOM[NB_ATOMS];
Expand Down Expand Up @@ -272,8 +262,8 @@ updateclientlist(void)
/* can only be called after the first window has been spawn */
xcb_query_tree_reply_t *reply = xcb_query_tree_reply(conn,
xcb_query_tree(conn, screen->root), 0);
xcb_delete_property(conn, screen->root, ATOM[atom_client_list]);
xcb_delete_property(conn, screen->root, ATOM[atom_client_list_st]);
xcb_delete_property(conn, screen->root, ewmh->_NET_CLIENT_LIST);
xcb_delete_property(conn, screen->root, ewmh->_NET_CLIENT_LIST_STACKING);

if (reply == NULL) {
addtoclientlist(0);
Expand Down Expand Up @@ -354,7 +344,7 @@ uint32_t getwmdesktop(xcb_drawable_t win)
{ // Get EWWM hint so we might know what workspace window win should be visible on.
// Returns either workspace, NET_WM_FIXED if this window should be
// visible on all workspaces or TWOBWM_NOWS if we didn't find any hints.
xcb_get_property_cookie_t cookie = xcb_get_property(conn, false, win, ATOM[atom_desktop],
xcb_get_property_cookie_t cookie = xcb_get_property(conn, false, win, ewmh->_NET_WM_DESKTOP,
XCB_GET_PROPERTY_TYPE_ANY, 0, sizeof(uint32_t));
xcb_get_property_reply_t *reply = xcb_get_property_reply(conn, cookie, NULL);
if (NULL==reply || 0 == xcb_get_property_value_length(reply)) { /* 0 if we didn't find it. */
Expand All @@ -374,7 +364,7 @@ get_unkil_state(xcb_drawable_t win)
xcb_get_property_reply_t *reply;
uint8_t wsp;

cookie = xcb_get_property(conn, false, win, ATOM[atom_unkillable],
cookie = xcb_get_property(conn, false, win, ewmh->_NET_WM_STATE_DEMANDS_ATTENTION,
XCB_GET_PROPERTY_TYPE_ANY, 0,sizeof(uint8_t));

reply = xcb_get_property_reply(conn, cookie, NULL);
Expand Down Expand Up @@ -457,14 +447,14 @@ addtoworkspace(struct client *client, uint32_t ws)
/* Set window hint property so we can survive a crash. Like "fixed" */
if (!client->fixed)
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, client->id,
ATOM[atom_desktop], XCB_ATOM_CARDINAL, 32, 1,
ewmh->_NET_WM_DESKTOP, XCB_ATOM_CARDINAL, 32, 1,
&ws
);
}
static void addtoclientlist(const xcb_drawable_t id)
{
xcb_change_property(conn, XCB_PROP_MODE_APPEND , screen->root, ATOM[atom_client_list] , XCB_ATOM_WINDOW, 32, 1,&id);
xcb_change_property(conn, XCB_PROP_MODE_APPEND , screen->root, ATOM[atom_client_list_st] , XCB_ATOM_WINDOW, 32, 1,&id);
xcb_change_property(conn, XCB_PROP_MODE_APPEND , screen->root, ewmh->_NET_CLIENT_LIST, XCB_ATOM_WINDOW, 32, 1,&id);
xcb_change_property(conn, XCB_PROP_MODE_APPEND , screen->root, ewmh->_NET_CLIENT_LIST_STACKING, XCB_ATOM_WINDOW, 32, 1,&id);
}

/* Change current workspace to ws */
Expand All @@ -476,7 +466,7 @@ changeworkspace_helper(const uint32_t ws)
struct item *item;

xcb_change_property(conn, XCB_PROP_MODE_REPLACE, screen->root,
ATOM[atom_current_desktop], XCB_ATOM_CARDINAL, 32, 1,
ewmh->_NET_CURRENT_DESKTOP, XCB_ATOM_CARDINAL, 32, 1,
&ws
);

Expand Down Expand Up @@ -544,7 +534,7 @@ fixwindow(struct client *client)
if (client->fixed) {
client->fixed = false;
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, client->id,
ATOM[atom_desktop], XCB_ATOM_CARDINAL, 32, 1,
ewmh->_NET_WM_DESKTOP, XCB_ATOM_CARDINAL, 32, 1,
&curws
);

Expand All @@ -558,7 +548,7 @@ fixwindow(struct client *client)
client->fixed = true;
ww = NET_WM_FIXED;
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, client->id,
ATOM[atom_desktop], XCB_ATOM_CARDINAL, 32, 1,
ewmh->_NET_WM_DESKTOP, XCB_ATOM_CARDINAL, 32, 1,
&ww
);

Expand All @@ -579,12 +569,12 @@ unkillablewindow(struct client *client)

if (client->unkillable) {
client->unkillable = false;
xcb_delete_property(conn, client->id, ATOM[atom_unkillable]);
xcb_delete_property(conn, client->id, ewmh->_NET_WM_STATE_DEMANDS_ATTENTION);
} else {
raisewindow(client->id);
client->unkillable = true;
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, client->id,
ATOM[atom_unkillable] , XCB_ATOM_CARDINAL, 8, 1,
ewmh->_NET_WM_STATE_DEMANDS_ATTENTION, XCB_ATOM_CARDINAL, 8, 1,
&client->unkillable
);
}
Expand Down Expand Up @@ -883,7 +873,7 @@ newwin(xcb_generic_event_t *ev)
/* Show window on screen. */
xcb_map_window(conn, client->id);
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, client->id,
ATOM[wm_state], ATOM[wm_state], 32, 2, data);
ewmh->_NET_WM_STATE, ewmh->_NET_WM_STATE, 32, 2, data);

centerpointer(e->window,client);
updateclientlist();
Expand Down Expand Up @@ -1618,7 +1608,7 @@ setfocus(struct client *client)// Set focus on window client.
XCB_INPUT_FOCUS_POINTER_ROOT, XCB_CURRENT_TIME);
xcb_window_t not_win = 0;
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, screen->root,
ATOM[atom_focus] , XCB_ATOM_WINDOW, 32, 1,
ewmh->_NET_ACTIVE_WINDOW, XCB_ATOM_WINDOW, 32, 1,
&not_win);

xcb_flush(conn);
Expand All @@ -1634,11 +1624,11 @@ setfocus(struct client *client)// Set focus on window client.
setunfocus(); /* Unset last focus. */

xcb_change_property(conn, XCB_PROP_MODE_REPLACE, client->id,
ATOM[wm_state], ATOM[wm_state], 32, 2, data);
ewmh->_NET_WM_STATE, ewmh->_NET_WM_STATE, 32, 2, data);
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, client->id,
XCB_CURRENT_TIME); /* Set new input focus. */
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, screen->root,
ATOM[atom_focus] , XCB_ATOM_WINDOW, 32, 1,&client->id);
ewmh->_NET_ACTIVE_WINDOW, XCB_ATOM_WINDOW, 32, 1,&client->id);

/* Remember the new window as the current focused window. */
focuswin = client;
Expand Down Expand Up @@ -2226,7 +2216,7 @@ hide(void)

long data[] = {
XCB_ICCCM_WM_STATE_ICONIC,
ATOM[wm_hidden],
ewmh->_NET_WM_STATE_HIDDEN,
XCB_NONE
};

Expand All @@ -2236,7 +2226,7 @@ hide(void)

xcb_unmap_window(conn, focuswin->id);
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, focuswin->id,
ATOM[wm_state], ATOM[wm_state], 32, 3, data);
ewmh->_NET_WM_STATE, ewmh->_NET_WM_STATE, 32, 3, data);

xcb_flush(conn);
}
Expand Down Expand Up @@ -2364,7 +2354,7 @@ deletewin()

/* Check if WM_DELETE is supported. */
cookie = xcb_icccm_get_wm_protocols_unchecked(conn, focuswin->id,
ATOM[wm_protocols]);
ewmh->WM_PROTOCOLS);

if (focuswin->id == top_win)
top_win = 0;
Expand All @@ -2378,7 +2368,7 @@ deletewin()
.format = 32,
.sequence = 0,
.window = focuswin->id,
.type = ATOM[wm_protocols],
.type = ewmh->WM_PROTOCOLS,
.data.data32 = {
ATOM[wm_delete_window],
XCB_CURRENT_TIME
Expand Down Expand Up @@ -2810,14 +2800,14 @@ clientmessage(xcb_generic_event_t *ev)

if ((e->type == ATOM[wm_change_state] && e->format==32
&& e->data.data32[0]==XCB_ICCCM_WM_STATE_ICONIC)
|| e->type == ATOM[atom_focus]) {
|| e->type == ewmh->_NET_ACTIVE_WINDOW) {
cl = findclient( &e->window);

if (NULL == cl)
return;

if ( false == cl->iconic ) {
if (e->type == ATOM[atom_focus])
if (e->type == ewmh->_NET_ACTIVE_WINDOW)
setfocus(cl);
else
hide();
Expand All @@ -2829,7 +2819,7 @@ clientmessage(xcb_generic_event_t *ev)
xcb_map_window(conn, cl->id);
setfocus(cl);
}
else if (e->type == ATOM[atom_current_desktop])
else if (e->type == ewmh->_NET_CURRENT_DESKTOP)
changeworkspace_helper(e->data.data32[0]);
}

Expand Down Expand Up @@ -3075,7 +3065,10 @@ setup(int scrno)
ewmh->_NET_SUPPORTING_WM_CHECK , ewmh->_NET_WM_STATE_HIDDEN,
ewmh->_NET_WM_ICON_NAME, ewmh->_NET_WM_WINDOW_TYPE,
ewmh->_NET_WM_WINDOW_TYPE_DOCK,
ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR, ewmh->_NET_WM_PID
ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR, ewmh->_NET_WM_PID,
ewmh->_NET_CLIENT_LIST, ewmh->_NET_CLIENT_LIST_STACKING,
ewmh->WM_PROTOCOLS, ewmh->_NET_WM_STATE,
ewmh->_NET_WM_STATE_DEMANDS_ATTENTION
};

xcb_ewmh_set_supported(ewmh, scrno, LENGTH(net_atoms), net_atoms);
Expand Down Expand Up @@ -3110,11 +3103,11 @@ setup(int scrno)
return false;

xcb_change_property(conn, XCB_PROP_MODE_REPLACE, screen->root,
ATOM[atom_current_desktop], XCB_ATOM_CARDINAL, 32, 1,
ewmh->_NET_CURRENT_DESKTOP, XCB_ATOM_CARDINAL, 32, 1,
&curws
);
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, screen->root,
ATOM[atom_nb_workspace] , XCB_ATOM_CARDINAL, 32, 1,
ewmh->_NET_NUMBER_OF_DESKTOPS, XCB_ATOM_CARDINAL, 32, 1,
&_WORKSPACES
);

Expand Down
4 changes: 2 additions & 2 deletions definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ enum {TWOBWM_RESIZE_LEFT, TWOBWM_RESIZE_DOWN, TWOBWM_RESIZE_UP, TWOBWM_RESIZE_RI
enum {TWOBWM_MOVE_LEFT, TWOBWM_MOVE_DOWN, TWOBWM_MOVE_UP, TWOBWM_MOVE_RIGHT,TWOBWM_MOVE_LEFT_SLOW, TWOBWM_MOVE_DOWN_SLOW, TWOBWM_MOVE_UP_SLOW, TWOBWM_MOVE_RIGHT_SLOW};
enum {TWOBWM_TELEPORT_CENTER_X, TWOBWM_TELEPORT_TOP_RIGHT, TWOBWM_TELEPORT_BOTTOM_RIGHT,TWOBWM_TELEPORT_CENTER, TWOBWM_TELEPORT_BOTTOM_LEFT, TWOBWM_TELEPORT_TOP_LEFT, TWOBWM_TELEPORT_CENTER_Y};
enum {BOTTOM_RIGHT, BOTTOM_LEFT, TOP_RIGHT, TOP_LEFT, MIDDLE};
enum {atom_desktop, atom_current_desktop, atom_unkillable, wm_delete_window, wm_change_state, wm_state, wm_protocols, atom_nb_workspace, atom_focus, atom_client_list, atom_client_list_st, wm_hidden, NB_ATOMS};
enum {wm_delete_window, wm_change_state, NB_ATOMS};
enum {TWOBWM_RESIZE_KEEP_ASPECT_GROW, TWOBWM_RESIZE_KEEP_ASPECT_SHRINK};
enum { TWOBWM_FULLSCREEN_OVERRIDE_OFFSETS, TWOBWM_FULLSCREEN};
enum {TWOBWM_FULLSCREEN, TWOBWM_FULLSCREEN_OVERRIDE_OFFSETS};
enum {TWOBWM_MAXIMIZE_HORIZONTALLY, TWOBWM_MAXIMIZE_VERTICALLY};
enum {TWOBWM_MAXHALF_FOLD_HORIZONTAL, TWOBWM_MAXHALF_UNFOLD_HORIZONTAL, TWOBWM_MAXHALF_HORIZONTAL_TOP, TWOBWM_MAXHALF_HORIZONTAL_BOTTOM, MAXHALF_UNUSED,TWOBWM_MAXHALF_VERTICAL_RIGHT, TWOBWM_MAXHALF_VERTICAL_LEFT, TWOBWM_MAXHALF_UNFOLD_VERTICAL, TWOBWM_MAXHALF_FOLD_VERTICAL};
enum {TWOBWM_PREVIOUS_SCREEN, TWOBWM_NEXT_SCREEN};
Expand Down
4 changes: 2 additions & 2 deletions hidden.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* hidden - A small program to listen all windows with WM_STATE set to
* hidden - A small program to listen all windows with _NET_WM_STATE set to
* Iconic.
*
* Copyright (c) 2012 Michael Cardell Widerkrantz, mc at the domain
Expand Down Expand Up @@ -281,7 +281,7 @@ int main(int argc, char **argv)
} /* while 1 */

init();
wm_state = getatom("WM_STATE");
wm_state = getatom("_NET_WM_STATE");
findhidden();
cleanup();
exit(0);
Expand Down

0 comments on commit 9efb565

Please sign in to comment.