Merge branch 'backport' into work
[dana/openbox.git] / openbox / prompt.c
index 3328a1b..d4dcbb7 100644 (file)
@@ -20,6 +20,7 @@
 #include "openbox.h"
 #include "screen.h"
 #include "client.h"
+#include "group.h"
 #include "event.h"
 #include "obt/display.h"
 #include "obt/keyboard.h"
@@ -27,6 +28,7 @@
 #include "gettext.h"
 
 static GList *prompt_list = NULL;
+static GList *prompt_msg_list = NULL;
 
 /* we construct these */
 static RrAppearance *prompt_a_bg;
@@ -120,6 +122,9 @@ void prompt_startup(gboolean reconfig)
 
 void prompt_shutdown(gboolean reconfig)
 {
+    while (prompt_msg_list)
+        prompt_cancel(prompt_msg_list->data);
+
     RrAppearanceFree(prompt_a_button);
     RrAppearanceFree(prompt_a_focus);
     RrAppearanceFree(prompt_a_press);
@@ -215,6 +220,9 @@ void prompt_unref(ObPrompt *self)
     if (self && --self->ref == 0) {
         gint i;
 
+        if (self->mapped)
+            prompt_hide(self);
+
         prompt_list = g_list_remove(prompt_list, self);
 
         for (i = 0; i < self->n_buttons; ++i) {
@@ -261,7 +269,6 @@ static void prompt_layout(ObPrompt *self)
         self->button[i].width = bw;
         self->button[i].height = bh;
         RrMinSize(prompt_a_focus, &bw, &bh);
-        g_print("button w %d h %d\n", bw, bh);
         self->button[i].width = MAX(self->button[i].width, bw);
         self->button[i].height = MAX(self->button[i].height, bh);
         RrMinSize(prompt_a_press, &bw, &bh);
@@ -349,14 +356,10 @@ static void prompt_resize(ObPrompt *self, gint w, gint h)
 static void setup_button_focus_tex(ObPromptElement *e, RrAppearance *a,
                                    gboolean on)
 {
-    gint l, r, t, b;
-
-    if (!on) {
-        gint i;
+    gint i, l, r, t, b;
 
-        for (i = 1; i < 5; ++i)
-            a->texture[i].type = on ? RR_TEXTURE_LINE_ART : RR_TEXTURE_NONE;
-    }
+    for (i = 1; i < 5; ++i)
+        a->texture[i].type = on ? RR_TEXTURE_LINE_ART : RR_TEXTURE_NONE;
 
     if (!on) return;
 
@@ -389,8 +392,6 @@ static void setup_button_focus_tex(ObPromptElement *e, RrAppearance *a,
     a->texture[4].data.lineart.x2 = e->width - r - 1;
     a->texture[4].data.lineart.y1 = t;
     a->texture[4].data.lineart.y2 = e->height - b - 1;
-
-    g_print("setting x2 %d\n", e->width - r - 1);
 }
 
 static void render_button(ObPrompt *self, ObPromptElement *e)
@@ -437,7 +438,7 @@ static void render_all(ObPrompt *self)
         render_button(self, &self->button[i]);
 }
 
-void prompt_show(ObPrompt *self, ObClient *parent)
+void prompt_show(ObPrompt *self, ObClient *parent, gboolean modal)
 {
     gint i;
 
@@ -459,8 +460,34 @@ void prompt_show(ObPrompt *self, ObClient *parent)
             break;
         }
 
-    XSetTransientForHint(obt_display, self->super.window,
-                         (parent ? parent->window : 0));
+    if (parent) {
+        Atom states[1];
+        gint nstates;
+        Window p;
+        XWMHints h;
+
+        if (parent->group) {
+            /* make it transient for the window's group */
+            h.flags = WindowGroupHint;
+            h.window_group = parent->group->leader;
+            p = obt_root(ob_screen);
+        }
+        else {
+            /* make it transient for the window directly */
+            h.flags = 0;
+            p = parent->window;
+        }
+
+        XSetWMHints(obt_display, self->super.window, &h);
+        OBT_PROP_SET32(self->super.window, WM_TRANSIENT_FOR, WINDOW, p);
+
+        states[0] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
+        nstates = (modal ? 1 : 0);
+        OBT_PROP_SETA32(self->super.window, NET_WM_STATE, ATOM,
+                        states, nstates);
+    }
+    else
+        OBT_PROP_ERASE(self->super.window, WM_TRANSIENT_FOR);
 
     /* set up the dialog and render it */
     prompt_layout(self);
@@ -579,3 +606,21 @@ void prompt_cancel(ObPrompt *self)
     if (self->func) self->func(self, self->cancel_result, self->data);
     prompt_hide(self);
 }
+
+static void prompt_show_message_cb(ObPrompt *p, int res, gpointer data)
+{
+    prompt_msg_list = g_list_remove(prompt_msg_list, p);
+    prompt_unref(p);
+}
+
+void prompt_show_message(const gchar *msg, const gchar *answer)
+{
+    ObPrompt *p;
+    ObPromptAnswer ans[] = {
+        { answer, 0 }
+    };
+
+    p = prompt_new(msg, ans, 1, 0, 0, prompt_show_message_cb, NULL);
+    prompt_msg_list = g_list_prepend(prompt_msg_list, p);
+    prompt_show(p, NULL, FALSE);
+}