2008-10-31 00:22:44 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Red Hat, Inc.
|
|
|
|
* Copyright (c) 2008 Intel Corp.
|
|
|
|
*
|
|
|
|
* Based on plugin skeleton by:
|
|
|
|
* Author: Tomas Frydrych <tf@linux.intel.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MUTTER_BUILDING_PLUGIN 1
|
|
|
|
#include <mutter-plugin.h>
|
|
|
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
2008-10-31 14:02:52 -04:00
|
|
|
#include <clutter/x11/clutter-x11.h>
|
2008-11-07 13:42:23 -05:00
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <gdk/gdkx.h>
|
2008-10-31 00:22:44 -04:00
|
|
|
#include <gjs/gjs.h>
|
|
|
|
#include <gmodule.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-11-07 13:42:23 -05:00
|
|
|
#include "display.h"
|
|
|
|
|
2008-10-31 00:22:44 -04:00
|
|
|
#include "shell-global.h"
|
|
|
|
|
|
|
|
static gboolean do_init (const char *params);
|
|
|
|
static gboolean reload (const char *params);
|
|
|
|
|
2008-10-31 14:02:52 -04:00
|
|
|
static gboolean xevent_filter (XEvent *xev);
|
2008-10-31 00:22:44 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the plugin struct; function pointers initialized in
|
|
|
|
* g_module_check_init().
|
|
|
|
*/
|
|
|
|
MUTTER_DECLARE_PLUGIN();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Plugin private data that we store in the .plugin_private member.
|
|
|
|
*/
|
|
|
|
typedef struct _PluginState
|
|
|
|
{
|
|
|
|
gboolean debug_mode : 1;
|
|
|
|
GjsContext *gjs_context;
|
2008-11-07 13:42:23 -05:00
|
|
|
Atom panel_action;
|
|
|
|
Atom panel_action_run_dialog;
|
|
|
|
Atom panel_action_main_menu;
|
2008-10-31 00:22:44 -04:00
|
|
|
} PluginState;
|
|
|
|
|
|
|
|
|
|
|
|
static PluginState *plugin_state;
|
|
|
|
|
|
|
|
const gchar * g_module_check_init (GModule *module);
|
|
|
|
const gchar *
|
|
|
|
g_module_check_init (GModule *module)
|
|
|
|
{
|
|
|
|
MutterPlugin *plugin = mutter_get_plugin ();
|
|
|
|
|
|
|
|
/* Human readable name (for use in UI) */
|
|
|
|
plugin->name = "GNOME Shell";
|
|
|
|
|
|
|
|
/* Plugin load time initialiser */
|
|
|
|
plugin->do_init = do_init;
|
|
|
|
|
|
|
|
/* The reload handler */
|
|
|
|
plugin->reload = reload;
|
|
|
|
|
2008-10-31 14:02:52 -04:00
|
|
|
/* Event handling */
|
|
|
|
plugin->xevent_filter = xevent_filter;
|
|
|
|
|
2008-11-21 09:02:09 -05:00
|
|
|
/* This will also create the ShellWM, which will set the appropriate
|
|
|
|
* window management callbacks in plugin.
|
|
|
|
*/
|
|
|
|
_shell_global_set_plugin (shell_global_get(), plugin);
|
|
|
|
|
2008-10-31 00:22:44 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Core of the plugin init function, called for initial initialization and
|
|
|
|
* by the reload() function. Returns TRUE on success.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
do_init (const char *params)
|
|
|
|
{
|
|
|
|
MutterPlugin *plugin = mutter_get_plugin();
|
2008-11-07 13:42:23 -05:00
|
|
|
MetaScreen *screen;
|
|
|
|
MetaDisplay *display;
|
2008-10-31 00:22:44 -04:00
|
|
|
GError *error = NULL;
|
|
|
|
int status;
|
|
|
|
const char *shell_js;
|
|
|
|
char **search_path;
|
|
|
|
|
2008-11-07 13:42:23 -05:00
|
|
|
screen = mutter_plugin_get_screen (plugin);
|
|
|
|
display = meta_screen_get_display (screen);
|
|
|
|
|
2008-10-31 00:22:44 -04:00
|
|
|
plugin_state = g_new0 (PluginState, 1);
|
|
|
|
|
|
|
|
if (params)
|
|
|
|
{
|
|
|
|
if (strstr (params, "debug"))
|
|
|
|
{
|
|
|
|
g_debug ("%s: Entering debug mode.", mutter_get_plugin()->name);
|
|
|
|
|
|
|
|
plugin_state->debug_mode = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shell_js = g_getenv("GNOME_SHELL_JS");
|
|
|
|
if (!shell_js)
|
|
|
|
shell_js = JSDIR;
|
|
|
|
|
|
|
|
search_path = g_strsplit(shell_js, ":", -1);
|
|
|
|
plugin_state->gjs_context = gjs_context_new_with_search_path(search_path);
|
|
|
|
g_strfreev(search_path);
|
|
|
|
|
2008-11-07 13:42:23 -05:00
|
|
|
plugin_state->panel_action = XInternAtom (meta_display_get_xdisplay (display),
|
|
|
|
"_GNOME_PANEL_ACTION", FALSE);
|
|
|
|
plugin_state->panel_action_run_dialog = XInternAtom (meta_display_get_xdisplay (display),
|
|
|
|
"_GNOME_PANEL_ACTION_RUN_DIALOG", FALSE);
|
|
|
|
plugin_state->panel_action_main_menu = XInternAtom (meta_display_get_xdisplay (display),
|
|
|
|
"_GNOME_PANEL_ACTION_MAIN_MENU", FALSE);
|
|
|
|
|
2008-10-31 00:22:44 -04:00
|
|
|
if (!gjs_context_eval (plugin_state->gjs_context,
|
|
|
|
"const Main = imports.ui.main; Main.start();",
|
|
|
|
-1,
|
|
|
|
"<main>",
|
|
|
|
&status,
|
|
|
|
&error))
|
|
|
|
{
|
|
|
|
g_warning ("Evaling main.js failed: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_plugin_private (PluginState *state)
|
|
|
|
{
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free (state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by the plugin manager when we stuff like the command line parameters
|
|
|
|
* changed.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
reload (const char *params)
|
|
|
|
{
|
|
|
|
PluginState *state;
|
|
|
|
|
|
|
|
state = plugin_state;
|
|
|
|
|
|
|
|
if (do_init (params))
|
|
|
|
{
|
|
|
|
/* Success; free the old state */
|
|
|
|
free_plugin_private (plugin_state);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Fail -- fall back to the old state. */
|
|
|
|
plugin_state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-07 13:42:23 -05:00
|
|
|
static gboolean
|
|
|
|
handle_panel_event (XEvent *xev)
|
|
|
|
{
|
|
|
|
MetaScreen *screen;
|
|
|
|
MetaDisplay *display;
|
|
|
|
XClientMessageEvent *xev_client;
|
|
|
|
Window root;
|
|
|
|
|
|
|
|
screen = mutter_plugin_get_screen (mutter_get_plugin ());
|
|
|
|
display = meta_screen_get_display (screen);
|
|
|
|
|
|
|
|
if (xev->type != ClientMessage)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
root = meta_screen_get_xroot (screen);
|
|
|
|
|
|
|
|
xev_client = (XClientMessageEvent*) xev;
|
|
|
|
if (!(xev_client->window == root &&
|
|
|
|
xev_client->message_type == plugin_state->panel_action &&
|
|
|
|
xev_client->format == 32))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (xev_client->data.l[0] == plugin_state->panel_action_run_dialog)
|
|
|
|
g_signal_emit_by_name (shell_global_get (), "panel-run-dialog",
|
|
|
|
(guint32) xev_client->data.l[1]);
|
|
|
|
else if (xev_client->data.l[0] == plugin_state->panel_action_main_menu)
|
|
|
|
g_signal_emit_by_name (shell_global_get (), "panel-main-menu",
|
|
|
|
(guint32) xev_client->data.l[1]);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-10-31 14:02:52 -04:00
|
|
|
static gboolean
|
|
|
|
xevent_filter (XEvent *xev)
|
|
|
|
{
|
2008-11-07 13:42:23 -05:00
|
|
|
if (handle_panel_event (xev))
|
|
|
|
return TRUE;
|
2008-10-31 14:02:52 -04:00
|
|
|
return clutter_x11_handle_event (xev) != CLUTTER_X11_FILTER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-10-31 00:22:44 -04:00
|
|
|
/*
|
|
|
|
* GModule unload function -- do any cleanup required.
|
|
|
|
*/
|
|
|
|
G_MODULE_EXPORT void g_module_unload (GModule *module);
|
|
|
|
G_MODULE_EXPORT void
|
|
|
|
g_module_unload (GModule *module)
|
|
|
|
{
|
|
|
|
free_plugin_private (plugin_state);
|
|
|
|
}
|
|
|
|
|