]> icculus.org git repositories - dana/openbox.git/blob - openbox/prompt.c
Merge branch 'backport' into work
[dana/openbox.git] / openbox / prompt.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    prompt.c for the Openbox window manager
4    Copyright (c) 2008        Dana Jansens
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "prompt.h"
20 #include "openbox.h"
21 #include "screen.h"
22 #include "client.h"
23 #include "group.h"
24 #include "event.h"
25 #include "obt/display.h"
26 #include "obt/keyboard.h"
27 #include "obt/prop.h"
28 #include "gettext.h"
29
30 static GList *prompt_list = NULL;
31
32 /* we construct these */
33 static RrAppearance *prompt_a_bg;
34 static RrAppearance *prompt_a_button;
35 static RrAppearance *prompt_a_focus;
36 static RrAppearance *prompt_a_press;
37 static RrAppearance *prompt_a_pfocus;
38 /* we change the max width which would screw with others */
39 static RrAppearance *prompt_a_msg;
40
41 /* sizing stuff */
42 #define OUTSIDE_MARGIN 4
43 #define MSG_BUTTON_SEPARATION 4
44 #define BUTTON_SEPARATION 4
45 #define BUTTON_VMARGIN 4
46 #define BUTTON_HMARGIN 12
47 #define MAX_WIDTH 400
48
49 static void prompt_layout(ObPrompt *self);
50 static void render_all(ObPrompt *self);
51 static void render_button(ObPrompt *self, ObPromptElement *e);
52 static void prompt_resize(ObPrompt *self, gint w, gint h);
53 static void prompt_run_callback(ObPrompt *self, gint result);
54
55 void prompt_startup(gboolean reconfig)
56 {
57     RrColor *c_button, *c_focus, *c_press, *c_pfocus;
58
59     /* note: this is not a copy, don't free it */
60     prompt_a_bg = ob_rr_theme->osd_hilite_bg;
61
62     prompt_a_button = RrAppearanceCopy(ob_rr_theme->a_focused_unpressed_close);
63     prompt_a_focus = RrAppearanceCopy(ob_rr_theme->a_hover_focused_close);
64     prompt_a_press = RrAppearanceCopy(ob_rr_theme->a_focused_pressed_close);
65     prompt_a_pfocus = RrAppearanceCopy(ob_rr_theme->a_focused_pressed_close);
66
67     c_button = prompt_a_button->texture[0].data.mask.color;
68     c_focus = prompt_a_focus->texture[0].data.mask.color;
69     c_press = prompt_a_press->texture[0].data.mask.color;
70     c_pfocus = prompt_a_press->texture[0].data.mask.color;
71
72     RrAppearanceRemoveTextures(prompt_a_button);
73     RrAppearanceRemoveTextures(prompt_a_focus);
74     RrAppearanceRemoveTextures(prompt_a_press);
75     RrAppearanceRemoveTextures(prompt_a_pfocus);
76
77     /* texture[0] is the text and texture[1-4] (for prompt_a_focus and
78        prompt_a_pfocus) is lineart to show where keyboard focus is */
79     RrAppearanceAddTextures(prompt_a_button, 1);
80     RrAppearanceAddTextures(prompt_a_focus, 5);
81     RrAppearanceAddTextures(prompt_a_press, 1);
82     RrAppearanceAddTextures(prompt_a_pfocus, 5);
83
84     /* totally cheating here.. */
85     prompt_a_button->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
86     prompt_a_focus->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
87     prompt_a_press->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
88     prompt_a_pfocus->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
89
90     prompt_a_button->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
91     prompt_a_focus->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
92     prompt_a_press->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
93     prompt_a_pfocus->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
94
95     prompt_a_button->texture[0].data.text.color = c_button;
96     prompt_a_focus->texture[0].data.text.color = c_focus;
97     prompt_a_press->texture[0].data.text.color = c_press;
98     prompt_a_pfocus->texture[0].data.text.color = c_pfocus;
99
100     prompt_a_focus->texture[1].data.lineart.color = c_focus;
101     prompt_a_focus->texture[2].data.lineart.color = c_focus;
102     prompt_a_focus->texture[3].data.lineart.color = c_focus;
103     prompt_a_focus->texture[4].data.lineart.color = c_focus;
104
105     prompt_a_pfocus->texture[1].data.lineart.color = c_press;
106     prompt_a_pfocus->texture[2].data.lineart.color = c_press;
107     prompt_a_pfocus->texture[3].data.lineart.color = c_press;
108     prompt_a_pfocus->texture[4].data.lineart.color = c_press;
109
110     prompt_a_msg = RrAppearanceCopy(ob_rr_theme->osd_hilite_label);
111     prompt_a_msg->texture[0].data.text.flow = TRUE;
112
113     if (reconfig) {
114         GList *it;
115         for (it = prompt_list; it; it = g_list_next(it)) {
116             ObPrompt *p = it->data;
117             prompt_layout(p);
118             render_all(p);
119         }
120     }
121 }
122
123 void prompt_shutdown(gboolean reconfig)
124 {
125     GList *it;
126
127     if (!reconfig) {
128         for (it = prompt_list; it; it = g_list_next(it)) {
129             ObPrompt *p = it->data;
130             if (p->cleanup) p->cleanup(p, p->data);
131         }
132
133         g_assert(prompt_list == NULL);
134     }
135
136     RrAppearanceFree(prompt_a_button);
137     RrAppearanceFree(prompt_a_focus);
138     RrAppearanceFree(prompt_a_press);
139     RrAppearanceFree(prompt_a_pfocus);
140     RrAppearanceFree(prompt_a_msg);
141 }
142
143 ObPrompt* prompt_new(const gchar *msg, const gchar *title,
144                      const ObPromptAnswer *answers, gint n_answers,
145                      gint default_result, gint cancel_result,
146                      ObPromptCallback func, ObPromptCleanup cleanup,
147                      gpointer data)
148 {
149     ObPrompt *self;
150     XSetWindowAttributes attrib;
151     gint i;
152
153     attrib.override_redirect = FALSE;
154
155     self = g_new0(ObPrompt, 1);
156     self->ref = 1;
157     self->func = func;
158     self->cleanup = cleanup;
159     self->data = data;
160     self->default_result = default_result;
161     self->cancel_result = cancel_result;
162     self->super.type = OB_WINDOW_CLASS_PROMPT;
163     self->super.window = XCreateWindow(obt_display, obt_root(ob_screen),
164                                        0, 0, 1, 1, 0,
165                                        CopyFromParent, InputOutput,
166                                        CopyFromParent,
167                                        CWOverrideRedirect,
168                                        &attrib);
169
170     /* make it a dialog type window */
171     OBT_PROP_SET32(self->super.window, NET_WM_WINDOW_TYPE, ATOM,
172                    OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG));
173
174     /* set the window's title */
175     if (title)
176         OBT_PROP_SETS(self->super.window, NET_WM_NAME, utf8, title);
177
178     /* listen for key presses on the window */
179     self->event_mask = KeyPressMask;
180
181     /* set up the text message widow */
182     self->msg.text = g_strdup(msg);
183     self->msg.window = XCreateWindow(obt_display, self->super.window,
184                                      0, 0, 1, 1, 0,
185                                      CopyFromParent, InputOutput,
186                                      CopyFromParent, 0, NULL);
187     XMapWindow(obt_display, self->msg.window);
188
189     /* set up the buttons from the answers */
190
191     self->n_buttons = n_answers;
192     if (!self->n_buttons)
193         self->n_buttons = 1;
194
195     self->button = g_new0(ObPromptElement, self->n_buttons);
196
197     if (n_answers == 0) {
198         g_assert(self->n_buttons == 1); /* should be set to this above.. */
199         self->button[0].text = g_strdup(_("OK"));
200     }
201     else {
202         g_assert(self->n_buttons > 0);
203         for (i = 0; i < self->n_buttons; ++i) {
204             self->button[i].text = g_strdup(answers[i].text);
205             self->button[i].result = answers[i].result;
206         }
207     }
208
209     for (i = 0; i < self->n_buttons; ++i) {
210         self->button[i].window = XCreateWindow(obt_display, self->super.window,
211                                                0, 0, 1, 1, 0,
212                                                CopyFromParent, InputOutput,
213                                                CopyFromParent, 0, NULL);
214         XMapWindow(obt_display, self->button[i].window);
215         window_add(&self->button[i].window, PROMPT_AS_WINDOW(self));
216
217         /* listen for button presses on the buttons */
218         XSelectInput(obt_display, self->button[i].window,
219                      ButtonPressMask | ButtonReleaseMask | ButtonMotionMask);
220     }
221
222     prompt_list = g_list_prepend(prompt_list, self);
223
224     return self;
225 }
226
227 void prompt_ref(ObPrompt *self)
228 {
229     ++self->ref;
230 }
231
232 void prompt_unref(ObPrompt *self)
233 {
234     if (self && --self->ref == 0) {
235         gint i;
236
237         if (self->mapped)
238             prompt_hide(self);
239
240         prompt_list = g_list_remove(prompt_list, self);
241
242         for (i = 0; i < self->n_buttons; ++i) {
243             window_remove(self->button[i].window);
244             XDestroyWindow(obt_display, self->button[i].window);
245         }
246
247         XDestroyWindow(obt_display, self->msg.window);
248         XDestroyWindow(obt_display, self->super.window);
249         g_free(self);
250     }
251 }
252
253 static void prompt_layout(ObPrompt *self)
254 {
255     gint l, r, t, b;
256     gint i;
257     gint allbuttonsw, allbuttonsh, buttonx;
258     gint w, h;
259     gint maxw;
260
261     RrMargins(prompt_a_bg, &l, &t, &r, &b);
262     l += OUTSIDE_MARGIN;
263     t += OUTSIDE_MARGIN;
264     r += OUTSIDE_MARGIN;
265     b += OUTSIDE_MARGIN;
266
267     {
268         Rect *area = screen_physical_area_all_monitors();
269         maxw = MIN(MAX_WIDTH, area->width*4/5);
270         g_free(area);
271     }
272
273     /* find the button sizes and how much space we need for them */
274     allbuttonsw = allbuttonsh = 0;
275     for (i = 0; i < self->n_buttons; ++i) {
276         gint bw, bh;
277
278         prompt_a_button->texture[0].data.text.string = self->button[i].text;
279         prompt_a_focus->texture[0].data.text.string = self->button[i].text;
280         prompt_a_press->texture[0].data.text.string = self->button[i].text;
281         prompt_a_pfocus->texture[0].data.text.string = self->button[i].text;
282         RrMinSize(prompt_a_button, &bw, &bh);
283         self->button[i].width = bw;
284         self->button[i].height = bh;
285         RrMinSize(prompt_a_focus, &bw, &bh);
286         self->button[i].width = MAX(self->button[i].width, bw);
287         self->button[i].height = MAX(self->button[i].height, bh);
288         RrMinSize(prompt_a_press, &bw, &bh);
289         self->button[i].width = MAX(self->button[i].width, bw);
290         self->button[i].height = MAX(self->button[i].height, bh);
291         RrMinSize(prompt_a_pfocus, &bw, &bh);
292         self->button[i].width = MAX(self->button[i].width, bw);
293         self->button[i].height = MAX(self->button[i].height, bh);
294
295         self->button[i].width += BUTTON_HMARGIN * 2;
296         self->button[i].height += BUTTON_VMARGIN * 2;
297
298         allbuttonsw += self->button[i].width + (i > 0 ? BUTTON_SEPARATION : 0);
299         allbuttonsh = MAX(allbuttonsh, self->button[i].height);
300     }
301
302     self->msg_wbound = MAX(allbuttonsw, maxw);
303
304     /* measure the text message area */
305     prompt_a_msg->texture[0].data.text.string = self->msg.text;
306     prompt_a_msg->texture[0].data.text.maxwidth = self->msg_wbound;
307     RrMinSize(prompt_a_msg, &self->msg.width, &self->msg.height);
308
309     /* width and height inside the outer margins */
310     w = MAX(self->msg.width, allbuttonsw);
311     h = self->msg.height + MSG_BUTTON_SEPARATION + allbuttonsh;
312
313     /* position the text message */
314     self->msg.x = l + (w - self->msg.width) / 2;
315     self->msg.y = t;
316
317     /* position the button buttons on the right of the dialog */
318     buttonx = l + w;
319     for (i = self->n_buttons - 1; i >= 0; --i) {
320         self->button[i].x = buttonx - self->button[i].width;
321         buttonx -= self->button[i].width + BUTTON_SEPARATION;
322         self->button[i].y = t + h - allbuttonsh;
323         self->button[i].y += (allbuttonsh - self->button[i].height) / 2;
324     }
325
326     /* size and position the toplevel window */
327     prompt_resize(self, w + l + r, h + t + b);
328
329     /* move and resize the internal windows */
330     XMoveResizeWindow(obt_display, self->msg.window,
331                       self->msg.x, self->msg.y,
332                       self->msg.width, self->msg.height);
333     for (i = 0; i < self->n_buttons; ++i)
334         XMoveResizeWindow(obt_display, self->button[i].window,
335                           self->button[i].x, self->button[i].y,
336                           self->button[i].width, self->button[i].height);
337 }
338
339 static void prompt_resize(ObPrompt *self, gint w, gint h)
340 {
341     XConfigureRequestEvent req;
342     XSizeHints hints;
343
344     self->width = w;
345     self->height = h;
346
347     /* the user can't resize the prompt */
348     hints.flags = PMinSize | PMaxSize;
349     hints.min_width = hints.max_width = w;
350     hints.min_height = hints.max_height = h;
351     XSetWMNormalHints(obt_display, self->super.window, &hints);
352
353     if (self->mapped) {
354         /* send a configure request like a normal client would */
355         req.type = ConfigureRequest;
356         req.display = obt_display;
357         req.parent = obt_root(ob_screen);
358         req.window = self->super.window;
359         req.width = w;
360         req.height = h;
361         req.value_mask = CWWidth | CWHeight;
362         XSendEvent(req.display, req.window, FALSE, StructureNotifyMask,
363                    (XEvent*)&req);
364     }
365     else
366         XResizeWindow(obt_display, self->super.window, w, h);
367 }
368
369 static void setup_button_focus_tex(ObPromptElement *e, RrAppearance *a,
370                                    gboolean on)
371 {
372     gint i, l, r, t, b;
373
374     for (i = 1; i < 5; ++i)
375         a->texture[i].type = on ? RR_TEXTURE_LINE_ART : RR_TEXTURE_NONE;
376
377     if (!on) return;
378
379     RrMargins(a, &l, &t, &r, &b);
380     l += MIN(BUTTON_HMARGIN, BUTTON_VMARGIN) / 2;
381     r += MIN(BUTTON_HMARGIN, BUTTON_VMARGIN) / 2;
382     t += MIN(BUTTON_HMARGIN, BUTTON_VMARGIN) / 2;
383     b += MIN(BUTTON_HMARGIN, BUTTON_VMARGIN) / 2;
384
385     /* top line */
386     a->texture[1].data.lineart.x1 = l;
387     a->texture[1].data.lineart.x2 = e->width - r - 1;
388     a->texture[1].data.lineart.y1 = t;
389     a->texture[1].data.lineart.y2 = t;
390
391     /* bottom line */
392     a->texture[2].data.lineart.x1 = l;
393     a->texture[2].data.lineart.x2 = e->width - r - 1;
394     a->texture[2].data.lineart.y1 = e->height - b - 1;
395     a->texture[2].data.lineart.y2 = e->height - b - 1;
396
397     /* left line */
398     a->texture[3].data.lineart.x1 = l;
399     a->texture[3].data.lineart.x2 = l;
400     a->texture[3].data.lineart.y1 = t;
401     a->texture[3].data.lineart.y2 = e->height - b - 1;
402
403     /* right line */
404     a->texture[4].data.lineart.x1 = e->width - r - 1;
405     a->texture[4].data.lineart.x2 = e->width - r - 1;
406     a->texture[4].data.lineart.y1 = t;
407     a->texture[4].data.lineart.y2 = e->height - b - 1;
408 }
409
410 static void render_button(ObPrompt *self, ObPromptElement *e)
411 {
412     RrAppearance *a;
413
414     if (e->pressed && self->focus == e) a = prompt_a_pfocus;
415     else if (self->focus == e)          a = prompt_a_focus;
416     else if (e->pressed)                a = prompt_a_press;
417     else                                a = prompt_a_button;
418
419     a->surface.parent = prompt_a_bg;
420     a->surface.parentx = e->x;
421     a->surface.parenty = e->y;
422
423     /* draw the keyfocus line */
424     if (a == prompt_a_pfocus || a == prompt_a_focus)
425         setup_button_focus_tex(e, a, TRUE);
426
427     a->texture[0].data.text.string = e->text;
428     RrPaint(a, e->window, e->width, e->height);
429
430     /* turn off the keyfocus line so that it doesn't affect size calculations
431      */
432     if (a == prompt_a_pfocus || a == prompt_a_focus)
433         setup_button_focus_tex(e, a, FALSE);
434 }
435
436 static void render_all(ObPrompt *self)
437 {
438     gint i;
439
440     RrPaint(prompt_a_bg, self->super.window, self->width, self->height);
441
442     prompt_a_msg->surface.parent = prompt_a_bg;
443     prompt_a_msg->surface.parentx = self->msg.x;
444     prompt_a_msg->surface.parenty = self->msg.y;
445
446     prompt_a_msg->texture[0].data.text.string = self->msg.text;
447     prompt_a_msg->texture[0].data.text.maxwidth = self->msg_wbound;
448     RrPaint(prompt_a_msg, self->msg.window, self->msg.width, self->msg.height);
449
450     for (i = 0; i < self->n_buttons; ++i)
451         render_button(self, &self->button[i]);
452 }
453
454 void prompt_show(ObPrompt *self, ObClient *parent, gboolean modal)
455 {
456     gint i;
457
458     if (self->mapped) {
459         /* activate the prompt */
460         OBT_PROP_MSG(ob_screen, self->super.window, NET_ACTIVE_WINDOW,
461                      1, /* from an application.. */
462                      event_curtime,
463                      0,
464                      0, 0);
465         return;
466     }
467
468     /* set the focused button (if not found then the first button is used) */
469     self->focus = &self->button[0];
470     for (i = 0; i < self->n_buttons; ++i)
471         if (self->button[i].result == self->default_result) {
472             self->focus = &self->button[i];
473             break;
474         }
475
476     if (parent) {
477         Atom states[1];
478         gint nstates;
479         Window p;
480         XWMHints h;
481
482         if (parent->group) {
483             /* make it transient for the window's group */
484             h.flags = WindowGroupHint;
485             h.window_group = parent->group->leader;
486             p = obt_root(ob_screen);
487         }
488         else {
489             /* make it transient for the window directly */
490             h.flags = 0;
491             p = parent->window;
492         }
493
494         XSetWMHints(obt_display, self->super.window, &h);
495         OBT_PROP_SET32(self->super.window, WM_TRANSIENT_FOR, WINDOW, p);
496
497         states[0] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
498         nstates = (modal ? 1 : 0);
499         OBT_PROP_SETA32(self->super.window, NET_WM_STATE, ATOM,
500                         states, nstates);
501     }
502     else
503         OBT_PROP_ERASE(self->super.window, WM_TRANSIENT_FOR);
504
505     /* set up the dialog and render it */
506     prompt_layout(self);
507     render_all(self);
508
509     client_manage(self->super.window, self);
510
511     self->mapped = TRUE;
512 }
513
514 void prompt_hide(ObPrompt *self)
515 {
516     XUnmapWindow(obt_display, self->super.window);
517     self->mapped = FALSE;
518 }
519
520 gboolean prompt_key_event(ObPrompt *self, XEvent *e)
521 {
522     gboolean shift;
523     guint shift_mask;
524
525     if (e->type != KeyPress) return FALSE;
526
527     shift_mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT);
528     shift = !!(e->xkey.state & shift_mask);
529
530     /* only accept shift */
531     if (e->xkey.state != 0 && e->xkey.state != shift_mask)
532         return FALSE;
533
534     if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE))
535         prompt_cancel(self);
536     else if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN) ||
537              e->xkey.keycode == ob_keycode(OB_KEY_SPACE))
538     {
539         prompt_run_callback(self, self->focus->result);
540     }
541     else if (e->xkey.keycode == ob_keycode(OB_KEY_TAB) ||
542              e->xkey.keycode == ob_keycode(OB_KEY_LEFT) ||
543              e->xkey.keycode == ob_keycode(OB_KEY_RIGHT))
544     {
545         gint i;
546         gboolean left;
547         ObPromptElement *oldfocus;
548
549         left = e->xkey.keycode == ob_keycode(OB_KEY_LEFT) ||
550             (e->xkey.keycode == ob_keycode(OB_KEY_TAB) && shift);
551         oldfocus = self->focus;
552
553         for (i = 0; i < self->n_buttons; ++i)
554             if (self->focus == &self->button[i]) break;
555         i += (left ? -1 : 1);
556         if (i < 0) i = self->n_buttons - 1;
557         else if (i >= self->n_buttons) i = 0;
558         self->focus = &self->button[i];
559
560         if (oldfocus != self->focus) render_button(self, oldfocus);
561         render_button(self, self->focus);
562     }
563     return TRUE;
564 }
565
566 gboolean prompt_mouse_event(ObPrompt *self, XEvent *e)
567 {
568     gint i;
569     ObPromptElement *but;
570
571     if (e->type != ButtonPress && e->type != ButtonRelease &&
572         e->type != MotionNotify) return FALSE;
573
574     /* find the button */
575     but = NULL;
576     for (i = 0; i < self->n_buttons; ++i)
577         if (self->button[i].window ==
578             (e->type == MotionNotify ? e->xmotion.window : e->xbutton.window))
579         {
580             but = &self->button[i];
581             break;
582         }
583     if (!but) return FALSE;
584
585     if (e->type == ButtonPress) {
586         ObPromptElement *oldfocus;
587
588         oldfocus = self->focus;
589
590         but->pressed = TRUE;
591         self->focus = but;
592
593         if (oldfocus != but) render_button(self, oldfocus);
594         render_button(self, but);
595     }
596     else if (e->type == ButtonRelease) {
597         if (but->pressed)
598             prompt_run_callback(self, but->result);
599     }
600     else if (e->type == MotionNotify) {
601         gboolean press;
602
603         press = (e->xmotion.x >= 0 && e->xmotion.y >= 0 &&
604                  e->xmotion.x < but->width && e->xmotion.y < but->height);
605
606         if (press != but->pressed) {
607             but->pressed = press;
608             render_button(self, but);
609         }
610     }
611     return TRUE;
612 }
613
614 void prompt_cancel(ObPrompt *self)
615 {
616     prompt_run_callback(self, self->cancel_result);
617 }
618
619 static gboolean prompt_show_message_cb(ObPrompt *p, int res, gpointer data)
620 {
621     return TRUE; /* call the cleanup func */
622 }
623
624 static void prompt_show_message_cleanup(ObPrompt *p, gpointer data)
625 {
626     prompt_unref(p);
627 }
628
629 ObPrompt* prompt_show_message(const gchar *msg, const gchar *title,
630                               const gchar *answer)
631 {
632     ObPrompt *p;
633     ObPromptAnswer ans[] = {
634         { answer, 0 }
635     };
636
637     p = prompt_new(msg, title, ans, 1, 0, 0,
638                    prompt_show_message_cb, prompt_show_message_cleanup, NULL);
639     prompt_show(p, NULL, FALSE);
640     return p;
641 }
642
643 static void prompt_run_callback(ObPrompt *self, gint result)
644 {
645     prompt_ref(self);
646     if (self->func) {
647         gboolean clean = self->func(self, self->focus->result, self->data);
648         if (clean && self->cleanup)
649             self->cleanup(self, self->data);
650     }
651     prompt_hide(self);
652     prompt_unref(self);
653 }