~compiz-team/compiz-core/oneiric.force_output_detection

« back to all changes in this revision

Viewing changes to gtk/window-decorator/actionmenu.c

  • Committer: Sam Spilsbury
  • Date: 2011-08-19 19:25:15 UTC
  • Revision ID: sam.spilsbury@canonical.com-20110819192515-xmaevli1jqqj8err
Add missing files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2006 Novell, Inc.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * Author: David Reveman <davidr@novell.com>
 
20
 */
 
21
 
 
22
#include "gtk-window-decorator.h"
 
23
 
 
24
static void
 
25
action_menu_unmap (GObject *object)
 
26
{
 
27
    action_menu_mapped = FALSE;
 
28
}
 
29
 
 
30
static void
 
31
position_action_menu (GtkMenu  *menu,
 
32
                      gint     *x,
 
33
                      gint     *y,
 
34
                      gboolean *push_in,
 
35
                      gpointer user_data)
 
36
{
 
37
    WnckWindow *win = (WnckWindow *) user_data;
 
38
    decor_frame_t  *frame = gwd_get_decor_frame (get_frame_type (win));
 
39
    decor_t    *d = g_object_get_data (G_OBJECT (win), "decor");
 
40
    gint       bx, by, width, height;
 
41
 
 
42
    wnck_window_get_client_window_geometry (win, x, y, &width, &height);
 
43
 
 
44
    if ((*theme_get_button_position) (d, BUTTON_MENU, width, height,
 
45
                                      &bx, &by, &width, &height))
 
46
        *x = *x - frame->win_extents.left + bx;
 
47
 
 
48
    gwd_decor_frame_unref (frame);
 
49
 
 
50
    if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
 
51
    {
 
52
        GtkRequisition req;
 
53
 
 
54
        gtk_widget_size_request (GTK_WIDGET (menu), &req);
 
55
        *x = MAX (0, *x - req.width + width);
 
56
    }
 
57
 
 
58
    *push_in = TRUE;
 
59
}
 
60
 
 
61
void
 
62
action_menu_map (WnckWindow *win,
 
63
                 long        button,
 
64
                 Time        time)
 
65
{
 
66
    GdkDisplay *gdkdisplay;
 
67
    GdkScreen  *screen;
 
68
 
 
69
    gdkdisplay = gdk_display_get_default ();
 
70
    screen     = gdk_display_get_default_screen (gdkdisplay);
 
71
 
 
72
    if (action_menu)
 
73
    {
 
74
        if (action_menu_mapped)
 
75
        {
 
76
            gtk_widget_destroy (action_menu);
 
77
            action_menu_mapped = FALSE;
 
78
            action_menu = NULL;
 
79
            return;
 
80
        }
 
81
        else
 
82
            gtk_widget_destroy (action_menu);
 
83
    }
 
84
 
 
85
    switch (wnck_window_get_window_type (win)) {
 
86
    case WNCK_WINDOW_DESKTOP:
 
87
    case WNCK_WINDOW_DOCK:
 
88
        /* don't allow window action */
 
89
        return;
 
90
    case WNCK_WINDOW_NORMAL:
 
91
    case WNCK_WINDOW_DIALOG:
 
92
 
 
93
#ifndef HAVE_LIBWNCK_2_19_4
 
94
    case WNCK_WINDOW_MODAL_DIALOG:
 
95
#endif
 
96
 
 
97
    case WNCK_WINDOW_TOOLBAR:
 
98
    case WNCK_WINDOW_MENU:
 
99
    case WNCK_WINDOW_UTILITY:
 
100
    case WNCK_WINDOW_SPLASHSCREEN:
 
101
        /* allow window action menu */
 
102
        break;
 
103
    }
 
104
 
 
105
    action_menu = wnck_create_window_action_menu (win);
 
106
 
 
107
    gtk_menu_set_screen (GTK_MENU (action_menu), screen);
 
108
 
 
109
    g_signal_connect_object (G_OBJECT (action_menu), "unmap",
 
110
                             G_CALLBACK (action_menu_unmap),
 
111
                             0, 0);
 
112
 
 
113
    gtk_widget_show (action_menu);
 
114
 
 
115
    if (!button || button == 1)
 
116
    {
 
117
        gtk_menu_popup (GTK_MENU (action_menu),
 
118
                        NULL, NULL,
 
119
                        position_action_menu, (gpointer) win,
 
120
                        button,
 
121
                        time);
 
122
    }
 
123
    else
 
124
    {
 
125
        gtk_menu_popup (GTK_MENU (action_menu),
 
126
                        NULL, NULL,
 
127
                        NULL, NULL,
 
128
                        button,
 
129
                        time);
 
130
    }
 
131
 
 
132
    action_menu_mapped = TRUE;
 
133
}