+/* * Copyright (c) 2012-2013 Bastien Dejean
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
#include <string.h>
#include <unistd.h>
#include "bspwm.h"
for (j = 0; d->name[j] != '\0' && (i + j) < sizeof(names); j++)
names[i + j] = d->name[j];
i += j;
- if (i <= sizeof(names))
+ if (i < sizeof(names))
names[i++] = '\0';
}
- names_len = i - 1;
+ if (i < 1)
+ return;
+ names_len = i - 1;
xcb_ewmh_set_desktop_names(ewmh, default_screen, names_len, names);
}
for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
wins[i++] = n->client->window;
- if (i != num_clients)
- return;
-
xcb_ewmh_set_client_list(ewmh, default_screen, num_clients, wins);
xcb_ewmh_set_client_list_stacking(ewmh, default_screen, num_clients, wins);
}
+bool ewmh_wm_state_add(client_t *c, xcb_atom_t state)
+{
+ if (c->num_states >= MAX_STATE)
+ return false;
+ for (int i = 0; i < c->num_states; i++)
+ if (c->wm_state[i] == state)
+ return false;
+ c->wm_state[c->num_states] = state;
+ c->num_states++;
+ xcb_ewmh_set_wm_state(ewmh, c->window, c->num_states, c->wm_state);
+ return true;
+}
+
+bool ewmh_wm_state_remove(client_t *c, xcb_atom_t state)
+{
+ for (int i = 0; i < c->num_states; i++)
+ if (c->wm_state[i] == state)
+ {
+ for (int j = i; j < (c->num_states - 1); j++)
+ c->wm_state[j] = c->wm_state[j + 1];
+ c->num_states--;
+ xcb_ewmh_set_wm_state(ewmh, c->window, c->num_states, c->wm_state);
+ return true;
+ }
+ return false;
+}
+
void ewmh_set_supporting(xcb_window_t win)
{
pid_t wm_pid = getpid();