ewmh: Introduce FOREACH_NONINTERNAL macro

This commit is contained in:
Orestis Floros 2019-05-03 15:38:37 +03:00
parent a574346964
commit 4a37d20602
No known key found for this signature in database
GPG Key ID: E9AD9F32E401E38F
1 changed files with 34 additions and 68 deletions

View File

@ -11,6 +11,11 @@
xcb_window_t ewmh_window; xcb_window_t ewmh_window;
#define FOREACH_NONINTERNAL \
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) \
TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) \
if (!con_is_internal(ws))
/* /*
* Updates _NET_CURRENT_DESKTOP with the current desktop number. * Updates _NET_CURRENT_DESKTOP with the current desktop number.
* *
@ -30,17 +35,12 @@ void ewmh_update_current_desktop(void) {
* noninternal workspaces. * noninternal workspaces.
*/ */
void ewmh_update_number_of_desktops(void) { void ewmh_update_number_of_desktops(void) {
Con *output; Con *output, *ws;
uint32_t idx = 0; uint32_t idx = 0;
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { FOREACH_NONINTERNAL {
Con *ws; idx++;
TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) { };
if (STARTS_WITH(ws->name, "__"))
continue;
++idx;
}
}
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
A__NET_NUMBER_OF_DESKTOPS, XCB_ATOM_CARDINAL, 32, 1, &idx); A__NET_NUMBER_OF_DESKTOPS, XCB_ATOM_CARDINAL, 32, 1, &idx);
@ -51,32 +51,21 @@ void ewmh_update_number_of_desktops(void) {
* list of NULL-terminated strings in UTF-8 encoding" * list of NULL-terminated strings in UTF-8 encoding"
*/ */
void ewmh_update_desktop_names(void) { void ewmh_update_desktop_names(void) {
Con *output; Con *output, *ws;
int msg_length = 0; int msg_length = 0;
/* count the size of the property message to set */ /* count the size of the property message to set */
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { FOREACH_NONINTERNAL {
Con *ws; msg_length += strlen(ws->name) + 1;
TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) { };
if (STARTS_WITH(ws->name, "__"))
continue;
msg_length += strlen(ws->name) + 1;
}
}
char desktop_names[msg_length]; char desktop_names[msg_length];
int current_position = 0; int current_position = 0;
/* fill the buffer with the names of the i3 workspaces */ /* fill the buffer with the names of the i3 workspaces */
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { FOREACH_NONINTERNAL {
Con *ws; for (size_t i = 0; i < strlen(ws->name) + 1; i++) {
TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) { desktop_names[current_position++] = ws->name[i];
if (STARTS_WITH(ws->name, "__"))
continue;
for (size_t i = 0; i < strlen(ws->name) + 1; i++) {
desktop_names[current_position++] = ws->name[i];
}
} }
} }
@ -89,32 +78,20 @@ void ewmh_update_desktop_names(void) {
* define the top left corner of each desktop's viewport. * define the top left corner of each desktop's viewport.
*/ */
void ewmh_update_desktop_viewport(void) { void ewmh_update_desktop_viewport(void) {
Con *output; Con *output, *ws;
int num_desktops = 0; int num_desktops = 0;
/* count number of desktops */ /* count number of desktops */
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { FOREACH_NONINTERNAL {
Con *ws; num_desktops++;
TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
if (STARTS_WITH(ws->name, "__"))
continue;
num_desktops++;
}
} }
uint32_t viewports[num_desktops * 2]; uint32_t viewports[num_desktops * 2];
int current_position = 0; int current_position = 0;
/* fill the viewport buffer */ /* fill the viewport buffer */
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { FOREACH_NONINTERNAL {
Con *ws; viewports[current_position++] = output->rect.x;
TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) { viewports[current_position++] = output->rect.y;
if (STARTS_WITH(ws->name, "__"))
continue;
viewports[current_position++] = output->rect.x;
viewports[current_position++] = output->rect.y;
}
} }
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
@ -354,18 +331,12 @@ Con *ewmh_get_workspace_by_index(uint32_t idx) {
uint32_t current_index = 0; uint32_t current_index = 0;
Con *output; Con *output, *ws;
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { FOREACH_NONINTERNAL {
Con *workspace; if (current_index == idx) {
TAILQ_FOREACH(workspace, &(output_get_content(output)->nodes_head), nodes) { return ws;
if (con_is_internal(workspace))
continue;
if (current_index == idx)
return workspace;
++current_index;
} }
current_index++;
} }
return NULL; return NULL;
@ -381,19 +352,14 @@ Con *ewmh_get_workspace_by_index(uint32_t idx) {
uint32_t ewmh_get_workspace_index(Con *con) { uint32_t ewmh_get_workspace_index(Con *con) {
uint32_t index = 0; uint32_t index = 0;
Con *workspace = con_get_workspace(con); Con *target_workspace = con_get_workspace(con);
Con *output; Con *output, *ws;
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { FOREACH_NONINTERNAL {
Con *current; if (ws == target_workspace) {
TAILQ_FOREACH(current, &(output_get_content(output)->nodes_head), nodes) { return index;
if (con_is_internal(current))
continue;
if (current == workspace)
return index;
++index;
} }
index++;
} }
return NET_WM_DESKTOP_NONE; return NET_WM_DESKTOP_NONE;