]> git.sur5r.net Git - i3/i3/blobdiff - src/util.c
Bugfix: partly revert f3880928, client->workspace was not updated (Thanks msi)
[i3/i3] / src / util.c
index e9f5472e7ec1e1a4c0cc4e5a14817ac0fb5b0b20..7990b56e3f460420969fb8570e787815b600d31d 100644 (file)
@@ -18,6 +18,9 @@
 #include <stdarg.h>
 #include <assert.h>
 #include <iconv.h>
+#if defined(__OpenBSD__)
+#include <sys/cdefs.h>
+#endif
 
 #include <xcb/xcb_icccm.h>
 
@@ -349,10 +352,13 @@ void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode)
                 if (container->mode == MODE_STACK || container->mode == MODE_TABBED)
                         goto after_stackwin;
 
-                /* When entering stacking mode, we need to open a window on which we can draw the
-                   title bars of the clients, it has height 1 because we don’t bother here with
-                   calculating the correct height - it will be adjusted when rendering anyways. */
-                Rect rect = {container->x, container->y, container->width, 1};
+                /* When entering stacking mode, we need to open a window on
+                 * which we can draw the title bars of the clients, it has
+                 * height 1 because we don’t bother here with calculating the
+                 * correct height - it will be adjusted when rendering anyways.
+                 * Also, we need to use max(width, 1) because windows cannot
+                 * be created with either width == 0 or height == 0. */
+                Rect rect = {container->x, container->y, max(container->width, 1), 1};
 
                 uint32_t mask = 0;
                 uint32_t values[2];
@@ -452,7 +458,7 @@ Client *get_matching_client(xcb_connection_t *conn, const char *window_classtitl
         }
 
         LOG("Getting clients for class \"%s\" / title \"%s\"\n", to_class, to_title);
-        for (int workspace = 0; workspace < 10; workspace++) {
+        for (int workspace = 0; workspace < num_workspaces; workspace++) {
                 if (workspaces[workspace].screen == NULL)
                         continue;
 
@@ -472,3 +478,40 @@ done:
         FREE(to_title_ucs);
         return matching;
 }
+
+#if defined(__OpenBSD__)
+
+/*
+ * Taken from FreeBSD
+ * Find the first occurrence of the byte string s in byte string l.
+ *
+ */
+void *memmem(const void *l, size_t l_len, const void *s, size_t s_len) {
+        register char *cur, *last;
+        const char *cl = (const char *)l;
+        const char *cs = (const char *)s;
+
+        /* we need something to compare */
+        if (l_len == 0 || s_len == 0)
+                return NULL;
+
+        /* "s" must be smaller or equal to "l" */
+        if (l_len < s_len)
+                return NULL;
+
+        /* special case where s_len == 1 */
+        if (s_len == 1)
+                return memchr(l, (int)*cs, l_len);
+
+        /* the last position where its possible to find "s" in "l" */
+        last = (char *)cl + l_len - s_len;
+
+        for (cur = (char *)cl; cur <= last; cur++)
+                if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
+                        return cur;
+
+        return NULL;
+}
+
+#endif
+