~mc-return/compiz/compiz.merge-src-screen.cpp-improvements

« back to all changes in this revision

Viewing changes to plugins/gnomecompat.cpp

  • Committer: Dennis kasprzyk
  • Author(s): Dennis Kasprzyk
  • Date: 2009-03-15 05:09:18 UTC
  • Revision ID: git-v1:163f6b6f3c3b7764987cbdf8e03cc355edeaa499
New generalized build system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2009 Danny Baumann
3
 
 *
4
 
 * Permission to use, copy, modify, distribute, and sell this software
5
 
 * and its documentation for any purpose is hereby granted without
6
 
 * fee, provided that the above copyright notice appear in all copies
7
 
 * and that both that copyright notice and this permission notice
8
 
 * appear in supporting documentation, and that the name of
9
 
 * Danny Baumann not be used in advertising or publicity pertaining to
10
 
 * distribution of the software without specific, written prior permission.
11
 
 * Danny Baumann makes no representations about the suitability of this
12
 
 * software for any purpose. It is provided "as is" without express or
13
 
 * implied warranty.
14
 
 *
15
 
 * DANNY BAUMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17
 
 * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
 
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20
 
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21
 
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 
 *
23
 
 * Author: Danny Baumann <dannybaumann@web.de>
24
 
 */
25
 
 
26
 
#include "gnomecompat.h"
27
 
 
28
 
COMPIZ_PLUGIN_20081216 (gnomecompat, GnomeCompatPluginVTable);
29
 
 
30
 
static bool
31
 
runCommand (CompAction          *action,
32
 
            CompAction::State   state,
33
 
            CompOption::Vector& options,
34
 
            unsigned int        commandOption)
35
 
{
36
 
    Window xid;
37
 
 
38
 
    GNOME_SCREEN (screen);
39
 
 
40
 
    xid = CompOption::getIntOptionNamed (options, "root", 0);
41
 
    if (xid != screen->root ())
42
 
        return false;
43
 
 
44
 
    screen->runCommand (gs->opt[commandOption].value ().s ());
45
 
 
46
 
    return true;
47
 
}
48
 
 
49
 
void
50
 
GnomeCompatScreen::panelAction (CompOption::Vector& options,
51
 
                                Atom                actionAtom)
52
 
{
53
 
    Window xid;
54
 
    XEvent event;
55
 
    Time   time;
56
 
 
57
 
    xid = CompOption::getIntOptionNamed (options, "root", 0);
58
 
    if (xid != screen->root ())
59
 
        return;
60
 
 
61
 
    time = CompOption::getIntOptionNamed (options, "time", CurrentTime);
62
 
 
63
 
    /* we need to ungrab the keyboard here, otherwise the panel main
64
 
       menu won't popup as it wants to grab the keyboard itself */
65
 
    XUngrabKeyboard (screen->dpy (), time);
66
 
 
67
 
    event.type                 = ClientMessage;
68
 
    event.xclient.window       = screen->root ();
69
 
    event.xclient.message_type = panelActionAtom;
70
 
    event.xclient.format       = 32;
71
 
    event.xclient.data.l[0]    = actionAtom;
72
 
    event.xclient.data.l[1]    = time;
73
 
    event.xclient.data.l[2]    = 0;
74
 
    event.xclient.data.l[3]    = 0;
75
 
    event.xclient.data.l[4]    = 0;
76
 
 
77
 
    XSendEvent (screen->dpy (), screen->root (), FALSE,
78
 
                StructureNotifyMask, &event);
79
 
}
80
 
 
81
 
static bool
82
 
showMainMenu (CompAction          *action,
83
 
              CompAction::State   state,
84
 
              CompOption::Vector& options)
85
 
{
86
 
    GNOME_SCREEN (screen);
87
 
 
88
 
    gs->panelAction (options, gs->panelMainMenuAtom);
89
 
 
90
 
    return true;
91
 
}
92
 
 
93
 
static bool
94
 
showRunDialog (CompAction          *action,
95
 
               CompAction::State   state,
96
 
               CompOption::Vector& options)
97
 
{
98
 
    GNOME_SCREEN (screen);
99
 
 
100
 
    gs->panelAction (options, gs->panelRunDialogAtom);
101
 
 
102
 
    return true;
103
 
}
104
 
 
105
 
#define COMMAND_BIND(opt) \
106
 
    boost::bind (runCommand, _1, _2, _3, opt)
107
 
 
108
 
static const CompMetadata::OptionInfo gnomeOptionInfo[] = {
109
 
    { "main_menu_key", "key", 0, showMainMenu, 0 },
110
 
    { "run_key", "key", 0, showRunDialog, 0 },
111
 
    { "command_screenshot", "string", 0, 0, 0 },
112
 
    { "run_command_screenshot_key", "key", 0,
113
 
        COMMAND_BIND (GNOME_OPTION_SCREENSHOT_CMD), 0 },
114
 
    { "command_window_screenshot", "string", 0, 0, 0 },
115
 
    { "run_command_window_screenshot_key", "key", 0,
116
 
        COMMAND_BIND (GNOME_OPTION_WINDOW_SCREENSHOT_CMD), 0 },
117
 
    { "command_terminal", "string", 0, 0, 0 },
118
 
    { "run_command_terminal_key", "key", 0,
119
 
        COMMAND_BIND (GNOME_OPTION_TERMINAL_CMD), 0 }
120
 
};
121
 
 
122
 
GnomeCompatScreen::GnomeCompatScreen (CompScreen *s) :
123
 
    PrivateHandler<GnomeCompatScreen, CompScreen> (s)
124
 
{
125
 
    if (!gnomecompatVTable->getMetadata ()->initOptions (gnomeOptionInfo,
126
 
                                                         GNOME_OPTION_NUM,
127
 
                                                         opt))
128
 
    {
129
 
        setFailed ();
130
 
        return;
131
 
    }
132
 
 
133
 
    panelActionAtom =
134
 
        XInternAtom (screen->dpy (), "_GNOME_PANEL_ACTION", FALSE);
135
 
    panelMainMenuAtom =
136
 
        XInternAtom (screen->dpy (), "_GNOME_PANEL_ACTION_MAIN_MENU", FALSE);
137
 
    panelRunDialogAtom =
138
 
        XInternAtom (screen->dpy (), "_GNOME_PANEL_ACTION_RUN_DIALOG", FALSE);
139
 
}
140
 
 
141
 
CompOption::Vector&
142
 
GnomeCompatScreen::getOptions ()
143
 
{
144
 
    return opt;
145
 
}
146
 
 
147
 
bool
148
 
GnomeCompatScreen::setOption (const char         *name,
149
 
                              CompOption::Value& value)
150
 
{
151
 
    CompOption *o;
152
 
 
153
 
    o = CompOption::findOption (opt, name, NULL);
154
 
    if (!o)
155
 
        return false;
156
 
 
157
 
    return CompOption::setOption (*o, value);
158
 
}
159
 
 
160
 
bool
161
 
GnomeCompatPluginVTable::init ()
162
 
{
163
 
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
164
 
        return false;
165
 
 
166
 
    getMetadata ()->addFromOptionInfo (gnomeOptionInfo, GNOME_OPTION_NUM);
167
 
    getMetadata ()->addFromFile (name ());
168
 
 
169
 
    return true;
170
 
}