add shell_global_[un]set_cursor

This functions set/unset the cursor on the stage window.
https://bugzilla.gnome.org/show_bug.cgi?id=607821
This commit is contained in:
Maxim Ermilov 2010-09-10 05:46:13 +04:00
parent 4f61f9a43d
commit 0e2ed0fb0b
2 changed files with 96 additions and 0 deletions

View File

@ -59,6 +59,7 @@ struct _ShellGlobal {
/* Displays the root window; see shell_global_create_root_pixmap_actor() */ /* Displays the root window; see shell_global_create_root_pixmap_actor() */
ClutterActor *root_pixmap; ClutterActor *root_pixmap;
GdkWindow *stage_window;
gint last_change_screen_width, last_change_screen_height; gint last_change_screen_width, last_change_screen_height;
@ -206,6 +207,7 @@ shell_global_init (ShellGlobal *global)
global->gtk_grab_active = FALSE; global->gtk_grab_active = FALSE;
global->root_pixmap = NULL; global->root_pixmap = NULL;
global->stage_window = NULL;
global->input_mode = SHELL_STAGE_INPUT_MODE_NORMAL; global->input_mode = SHELL_STAGE_INPUT_MODE_NORMAL;
@ -435,6 +437,88 @@ shell_global_set_stage_input_mode (ShellGlobal *global,
} }
} }
/**
* shell_global_set_cursor:
* @global: A #ShellGlobal
* @type: the type of the cursor
*
* Set the cursor on the stage window.
*/
void
shell_global_set_cursor (ShellGlobal *global,
ShellCursor type)
{
const char *name;
GdkCursor *cursor;
switch (type)
{
case SHELL_CURSOR_DND_IN_DRAG:
name = "dnd-none";
break;
case SHELL_CURSOR_DND_MOVE:
name = "dnd-move";
break;
case SHELL_CURSOR_DND_COPY:
name = "dnd-copy";
break;
case SHELL_CURSOR_DND_UNSUPPORTED_TARGET:
name = "dnd-none";
break;
default:
g_return_if_reached ();
}
cursor = gdk_cursor_new_from_name (gdk_display_get_default (), name);
if (!cursor)
{
GdkCursorType cursor_type;
switch (type)
{
case SHELL_CURSOR_DND_IN_DRAG:
cursor_type = GDK_FLEUR;
break;
case SHELL_CURSOR_DND_MOVE:
cursor_type = GDK_TARGET;
break;
case SHELL_CURSOR_DND_COPY:
cursor_type = GDK_PLUS;
break;
case SHELL_CURSOR_DND_UNSUPPORTED_TARGET:
cursor_type = GDK_X_CURSOR;
break;
default:
g_return_if_reached ();
}
cursor = gdk_cursor_new (cursor_type);
}
if (!global->stage_window)
{
ClutterStage *stage = CLUTTER_STAGE (mutter_plugin_get_stage (global->plugin));
global->stage_window = gdk_window_foreign_new (clutter_x11_get_stage_window (stage));
}
gdk_window_set_cursor (global->stage_window, cursor);
gdk_cursor_unref (cursor);
}
/**
* shell_global_unset_cursor:
* @global: A #ShellGlobal
*
* Unset the cursor on the stage window.
*/
void
shell_global_unset_cursor (ShellGlobal *global)
{
if (!global->stage_window) /* cursor has never been set */
return;
gdk_window_set_cursor (global->stage_window, NULL);
}
/** /**
* shell_global_set_stage_input_region: * shell_global_set_stage_input_region:
* @global: the #ShellGlobal * @global: the #ShellGlobal

View File

@ -34,6 +34,18 @@ gboolean shell_clutter_texture_set_from_pixbuf (ClutterTexture *texture,
ShellGlobal *shell_global_get (void); ShellGlobal *shell_global_get (void);
typedef enum {
SHELL_CURSOR_DND_IN_DRAG,
SHELL_CURSOR_DND_UNSUPPORTED_TARGET,
SHELL_CURSOR_DND_MOVE,
SHELL_CURSOR_DND_COPY
} ShellCursor;
void shell_global_set_cursor (ShellGlobal *global,
ShellCursor type);
void shell_global_unset_cursor (ShellGlobal *global);
MetaScreen *shell_global_get_screen (ShellGlobal *global); MetaScreen *shell_global_get_screen (ShellGlobal *global);
GdkScreen *shell_global_get_gdk_screen (ShellGlobal *global); GdkScreen *shell_global_get_gdk_screen (ShellGlobal *global);