]> Dogcows Code - chaz/openbox/blobdiff - cwmcc/client_props.c
raise menus above clients.
[chaz/openbox] / cwmcc / client_props.c
index 43641324dd4b0e32757b858d57f1ae7c099093e3..4ca51d390a16a9e83cc125c8f16a5c544f9c4516 100644 (file)
@@ -2,56 +2,78 @@
 #include "atom.h"
 #include "prop.h"
 #include "client_props.h"
-#include "render/render.h"
 
 #include <X11/Xutil.h>
+#include <string.h>
 
-void cwmcc_client_get_protocols(Window win, Atom **protocols)
+void cwmcc_client_get_protocols(Window win, Atom **protocols, gulong *num)
 {
-    gulong num;
-
-    if (!prop_get_array32(win, CWMCC_ATOM(client, wm_protocols),
-                          CWMCC_ATOM(type, atom), protocols, &num)) {
+    if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, wm_protocols),
+                                CWMCC_ATOM(type, atom), protocols, num)) {
+        g_warning("Failed to read WM_PROTOCOLS from 0x%lx", win);
         *protocols = NULL;
+        *num = 0;
     }
 }
 
-int cwmcc_client_get_wm_state(Window win)
+void cwmcc_client_set_protocols(Window win, Atom *protocols, gulong num)
 {
-    gulong s;
+    cwmcc_prop_set_array32(win, CWMCC_ATOM(client, wm_state),
+                           CWMCC_ATOM(type, atom), protocols, num);
+}
 
-    if (!prop_get32(win, CWMCC_ATOM(client, wm_state),
-                    CWMCC_ATOM(client, wm_state), &s)) {
+void cwmcc_client_get_wm_state(Window win, gulong *state)
+{
+    if (!cwmcc_prop_get32(win, CWMCC_ATOM(client, wm_state),
+                          CWMCC_ATOM(client, wm_state), state)) {
         g_warning("Failed to read WM_STATE from 0x%lx", win);
-        s = NormalState;
+        *state = NormalState;
     }
-    return s;
+}
+
+void cwmcc_client_set_wm_state(Window win, gulong state)
+{
+    cwmcc_prop_set32(win, CWMCC_ATOM(client, wm_state),
+                     CWMCC_ATOM(client, wm_state), state);
 }
 
 void cwmcc_client_get_name(Window win, char **name)
 {
-    if (!prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_name), name))
-        if (!prop_get_string_locale(win, CWMCC_ATOM(client, wm_name), name)) {
+    if (!cwmcc_prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_name),
+                                    name))
+        if (!cwmcc_prop_get_string_locale(win, CWMCC_ATOM(client, wm_name),
+                                          name)) {
             g_warning("Failed to read a name from 0x%lx", win);
             *name = g_strdup("Unnamed Window");
         }
 }
 
+void cwmcc_client_set_name(Window win, char *name)
+{
+    cwmcc_prop_set_string_utf8(win, CWMCC_ATOM(client, net_wm_name), name);
+}
+
 void cwmcc_client_get_icon_name(Window win, char **name)
 {
-    if (!prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_icon_name), name))
-        if (!prop_get_string_locale(win,
-                                    CWMCC_ATOM(client, wm_icon_name), name)) {
+    if (!cwmcc_prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_icon_name),
+                                    name))
+        if (!cwmcc_prop_get_string_locale(win,CWMCC_ATOM(client, wm_icon_name),
+                                          name)) {
             g_warning("Failed to read an icon name from 0x%lx", win);
             *name = g_strdup("Unnamed Window");
         }
 }
 
+void cwmcc_client_set_icon_name(Window win, char *name)
+{
+    cwmcc_prop_set_string_utf8(win, CWMCC_ATOM(client, net_wm_icon_name),name);
+}
+
 void cwmcc_client_get_class(Window win, char **class, char **name)
 {
     char **s;
 
-    if (!prop_get_strings_locale(win, CWMCC_ATOM(client, wm_class), &s)) {
+    if (!cwmcc_prop_get_strings_locale(win, CWMCC_ATOM(client, wm_class), &s)){
         g_warning("Failed to read WM_CLASS from 0x%lx", win);
         *class = g_strdup("");
         *name = g_strdup("");
@@ -74,8 +96,8 @@ void cwmcc_client_get_class(Window win, char **class, char **name)
 
 void cwmcc_client_get_role(Window win, char **role)
 {
-    if (!prop_get_string_locale(win,
-                                CWMCC_ATOM(client, wm_window_role), role)) {
+    if (!cwmcc_prop_get_string_locale(win, CWMCC_ATOM(client, wm_window_role),
+                                      role)) {
         g_warning("Failed to read WM_WINDOW_ROLE from 0x%lx", win);
         *role = g_strdup("");
     }
@@ -85,8 +107,8 @@ void cwmcc_client_get_mwmhints(Window win, struct Cwmcc_MwmHints *hints)
 {
     gulong *l = NULL, num;
 
-    if (!prop_get_array32(win, CWMCC_ATOM(client, motif_wm_hints),
-                          CWMCC_ATOM(client, motif_wm_hints), &l, &num)) {
+    if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, motif_wm_hints),
+                                CWMCC_ATOM(client, motif_wm_hints), &l, &num)){
         g_warning("Failed to read Motif WM Hints from 0x%lx", win);
         hints->flags = 0;
     } else if (num < 3) {
@@ -102,44 +124,58 @@ void cwmcc_client_get_mwmhints(Window win, struct Cwmcc_MwmHints *hints)
 
 void cwmcc_client_get_desktop(Window win, gulong *desk)
 {
-    if (!prop_get32(win, CWMCC_ATOM(client, net_wm_desktop),
-                    CWMCC_ATOM(type, cardinal), desk)) {
+    if (!cwmcc_prop_get32(win, CWMCC_ATOM(client, net_wm_desktop),
+                          CWMCC_ATOM(type, cardinal), desk)) {
         g_warning("Failed to read NET_WM_DESKTOP from 0x%lx", win);
         *desk = 0;
     }
 }
 
-void cwmcc_client_get_type(Window win, gulong **types)
+void cwmcc_client_set_desktop(Window win, gulong desk)
 {
-    gulong num;
+    cwmcc_prop_set32(win, CWMCC_ATOM(client, net_wm_desktop),
+                     CWMCC_ATOM(type, cardinal), desk);
+}
 
-    if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_window_type),
-                    CWMCC_ATOM(type, atom), types, &num)) {
+void cwmcc_client_get_type(Window win, gulong **types, gulong *num)
+{
+    if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, net_wm_window_type),
+                                CWMCC_ATOM(type, atom), types, num)) {
         g_warning("Failed to read NET_WM_WINDOW_TYPE from 0x%lx", win);
-        *types = g_new(Atom, 2);
+        *types = g_new(Atom, 1);
         (*types)[0] = CWMCC_ATOM(data, net_wm_window_type_normal);
-        (*types)[1] = 0;
+        *num = 1;
     }
 }
 
-void cwmcc_client_get_state(Window win, gulong **states)
+void cwmcc_client_set_type(Window win, gulong *types, gulong num)
 {
-    gulong num;
+    cwmcc_prop_set_array32(win, CWMCC_ATOM(client, net_wm_window_type),
+                           CWMCC_ATOM(type, atom), types, num);
+}
 
-    if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_state),
-                    CWMCC_ATOM(type, atom), states, &num)) {
+void cwmcc_client_get_state(Window win, gulong **states, gulong *num)
+{
+    if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, net_wm_state),
+                                CWMCC_ATOM(type, atom), states, num)) {
         g_warning("Failed to read NET_WM_STATE from 0x%lx", win);
-        *states = g_new(Atom, 1);
-        (*states)[0] = 0;
+        *states = NULL;
+        *num = 0;
     }
 }
 
+void cwmcc_client_set_state(Window win, gulong *states, gulong num)
+{
+    cwmcc_prop_set_array32(win, CWMCC_ATOM(client, net_wm_state),
+                           CWMCC_ATOM(type, atom), states, num);
+}
+
 void cwmcc_client_get_strut(Window win, int *l, int *t, int *r, int *b)
 {
     gulong *data = NULL, num;
 
-    if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_strut),
-                    CWMCC_ATOM(type, cardinal), &data, &num)) {
+    if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, net_wm_strut),
+                                CWMCC_ATOM(type, cardinal), &data, &num)) {
         g_warning("Failed to read NET_WM_STRUT from 0x%lx", win);
         *l = *t = *r = *b = 0;
     } else if (num != 4) {
@@ -151,7 +187,19 @@ void cwmcc_client_get_strut(Window win, int *l, int *t, int *r, int *b)
         *t = data[2];
         *b = data[3];
     }
-    g_free(l);
+    g_free(data);
+}
+
+void cwmcc_client_set_strut(Window win, int l, int t, int r, int b)
+{
+    gulong data[4];
+
+    data[0] = l;
+    data[1] = r;
+    data[2] = t;
+    data[3] = b;
+    cwmcc_prop_set_array32(win, CWMCC_ATOM(client, net_wm_strut),
+                           CWMCC_ATOM(type, cardinal), data, 4);
 }
 
 static void convert_pixmap_to_icon(Pixmap pix, Pixmap mask,
@@ -193,15 +241,15 @@ static void convert_pixmap_to_icon(Pixmap pix, Pixmap mask,
     icon->data = NULL;
 }
 
-void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons)
+void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons, gulong *num)
 {
-    gulong *data = NULL, num;
+    gulong *data = NULL;
     gulong w, h, i;
     int j;
     int nicons;
 
-    if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_icon),
-                          CWMCC_ATOM(type, cardinal), &data, &num)) {
+    if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, net_wm_icon),
+                                CWMCC_ATOM(type, cardinal), &data, num)) {
         g_warning("Failed to read NET_WM_ICON from 0x%lx", win);
         *icons = NULL;
         nicons = 0;
@@ -209,16 +257,15 @@ void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons)
        /* figure out how many valid icons are in here */
        i = 0;
         nicons = 0;
-       while (num - i > 2) {
+       while (*num - i > 2) {
            w = data[i++];
            h = data[i++];
            i += w * h;
-           if (i > num) break;
+           if (i > *num) break;
            ++nicons;
        }
 
-       *icons = g_new(struct Cwmcc_Icon, nicons + 1);
-        (*icons)[nicons].data = NULL;
+       *icons = g_new(struct Cwmcc_Icon, nicons);
     
        /* store the icons */
        i = 0;
@@ -228,16 +275,16 @@ void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons)
             (*icons)[j].data =
                 g_memdup(&data[i], w * h * sizeof(gulong));
            i += w * h;
-           g_assert(i <= num);
+           g_assert(i <= *num);
        }
     }
     g_free(data);
 
     data = NULL;
-    if (!prop_get_array32(win, CWMCC_ATOM(client, kwm_win_icon),
-                          CWMCC_ATOM(client, kwm_win_icon), &data, &num)) {
+    if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, kwm_win_icon),
+                                CWMCC_ATOM(client, kwm_win_icon), &data, num)){
         g_warning("Failed to read KWM_WIN_ICON from 0x%lx", win);
-    } else if (num != 2) {
+    } else if (*num != 2) {
         g_warning("Read invalid KWM_WIN_ICON from 0x%lx", win);
     } else {
         Pixmap p, m;
@@ -249,21 +296,23 @@ void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons)
         convert_pixmap_to_icon(p, m, &icon);
 
         if (icon.data) {
-            *icons = g_renew(struct Cwmcc_Icon, *icons, nicons + 2);
-            (*icons[nicons + 1]).data = NULL;
-            g_memmove(&(*icons)[nicons], &icon, sizeof(struct Cwmcc_Icon));
+            ++nicons;
+            *icons = g_renew(struct Cwmcc_Icon, *icons, nicons);
+            (*icons[nicons]).data = NULL;
+            g_memmove(&(*icons)[nicons-1], &icon, sizeof(struct Cwmcc_Icon));
         }
     }
     g_free(data);
 
+    *num = nicons;
 }
 
 void cwmcc_client_get_premax(Window win, int *x, int *y, int *w, int *h)
 {
     gulong *l = NULL, num;
 
-    if (!prop_get_array32(win, CWMCC_ATOM(client, openbox_premax),
-                    CWMCC_ATOM(type, cardinal), &l, &num)) {
+    if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, openbox_premax),
+                                CWMCC_ATOM(type, cardinal), &l, &num)) {
         g_warning("Failed to read OPENBOX_PREMAX from 0x%lx", win);
         *x = *y = *w = *h = 0;
     } else if (num != 4) {
@@ -286,7 +335,6 @@ void cwmcc_client_set_premax(Window win, int x, int y, int w, int h)
     l[1] = y;
     l[2] = w;
     l[3] = h;
-    XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, openbox_premax),
-                    CWMCC_ATOM(type, cardinal), 32, PropModeReplace,
-                    (guchar*)l, 4);
+    cwmcc_prop_set_array32(win, CWMCC_ATOM(client, openbox_premax),
+                           CWMCC_ATOM(type, cardinal), l, 4);
 }
This page took 0.034855 seconds and 4 git commands to generate.