]> Dogcows Code - chaz/openbox/blobdiff - openbox/popup.c
make key grabbing per window instead of always root
[chaz/openbox] / openbox / popup.c
index f20aa006170678be0160e921357dd4e2c568697e..a550e815856b668b1e3d39e8c2a55dd59ab8b607 100644 (file)
@@ -1,13 +1,18 @@
 #include "openbox.h"
 #include "frame.h"
+#include "window.h"
+#include "stacking.h"
 #include "render/render.h"
 #include "render/theme.h"
 
 typedef struct Popup {
-    gboolean hasicon;
+    ObWindow obwin;
     Window bg;
+
     Window icon;
     Window text;
+
+    gboolean hasicon;
     Appearance *a_bg;
     Appearance *a_icon;
     Appearance *a_text;
@@ -16,16 +21,21 @@ typedef struct Popup {
     int y;
     int w;
     int h;
+    gboolean mapped;
 } Popup;
 
 Popup *popup_new(gboolean hasicon)
 {
     Popup *self = g_new(Popup, 1);
+    self->obwin.type = Window_Internal;
     self->hasicon = hasicon;
     self->bg = None;
     self->a_text = NULL;
     self->gravity = NorthWestGravity;
     self->x = self->y = self->w = self->h = 0;
+    self->mapped = FALSE;
+    stacking_add(INTERNAL_AS_WINDOW(self));
+    stacking_raise(INTERNAL_AS_WINDOW(self));
     return self;
 }
 
@@ -41,6 +51,7 @@ void popup_free(Popup *self)
     }
     if (self->a_text)
         appearance_free(self->a_text);
+    stacking_remove(self);
     g_free(self);
 }
 
@@ -72,7 +83,7 @@ void popup_size_to_string(Popup *self, char *text)
 
     self->h = texth + theme_bevel * 2;
     iconw = (self->hasicon ? texth : 0);
-    self->w = textw + iconw + theme_bevel * 3;
+    self->w = textw + iconw + theme_bevel * (self->hasicon ? 3 : 2);
 }
 
 void popup_show(Popup *self, char *text, Icon *icon)
@@ -138,9 +149,9 @@ void popup_show(Popup *self, char *text, Icon *icon)
     iconw = (self->hasicon ? texth : 0);
     if (self->w) {
         w = self->w;
-        textw = w - (iconw + theme_bevel * 3);
+        textw = w - (iconw + theme_bevel * (self->hasicon ? 3 : 2));
     } else
-        w = textw + iconw + theme_bevel * 3;
+        w = textw + iconw + theme_bevel * (self->hasicon ? 3 : 2);
     /* sanity checks to avoid crashes! */
     if (w < 1) w = 1;
     if (h < 1) h = 1;
@@ -185,10 +196,12 @@ void popup_show(Popup *self, char *text, Icon *icon)
     RECT_SET(self->a_text->texture[0].position, theme_bevel, theme_bevel,
              textw - theme_bevel * 2, texth - theme_bevel * 2);
     self->a_text->surface.data.planar.parent = self->a_bg;
-    self->a_text->surface.data.planar.parentx = iconw + theme_bevel * 2;
+    self->a_text->surface.data.planar.parentx = iconw +
+        theme_bevel * (self->hasicon ? 2 : 1);
     self->a_text->surface.data.planar.parenty = theme_bevel;
     XMoveResizeWindow(ob_display, self->text,
-                      iconw + theme_bevel * 2, theme_bevel, textw, texth);
+                      iconw + theme_bevel * (self->hasicon ? 2 : 1),
+                      theme_bevel, textw, texth);
 
     if (self->hasicon) {
         if (iconw < 1) iconw = 1; /* sanity check for crashes */
@@ -206,10 +219,17 @@ void popup_show(Popup *self, char *text, Icon *icon)
     if (self->hasicon)
         paint(self->icon, self->a_icon);
 
-    XMapWindow(ob_display, self->bg);
+    if (!self->mapped) {
+        XMapWindow(ob_display, self->bg);
+        stacking_raise(INTERNAL_AS_WINDOW(self));
+        self->mapped = TRUE;
+    }
 }
 
 void popup_hide(Popup *self)
 {
-    XUnmapWindow(ob_display, self->bg);
+    if (self->mapped) {
+        XUnmapWindow(ob_display, self->bg);
+        self->mapped = FALSE;
+    }
 }
This page took 0.02224 seconds and 4 git commands to generate.