~mterry/ubuntu/natty/gnome-shell/wip

« back to all changes in this revision

Viewing changes to src/shell-global.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-10-12 22:44:00 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091012224400-k91p42yvou07i525
Tags: 2.28.0-0ubuntu1
* New upstream version
* debian/control:
  - updated build requirement
* debian/patches/80_git_change_fix_alt_tab_ressource_usage.patch:
  - git change to fix ressources not being freed on alt-tab

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
  
41
41
  MutterPlugin *plugin;
42
42
  ShellWM *wm;
 
43
  const char *datadir;
43
44
  const char *imagedir;
44
45
  const char *configdir;
45
46
 
57
58
  PROP_STAGE,
58
59
  PROP_WINDOW_GROUP,
59
60
  PROP_WINDOW_MANAGER,
 
61
  PROP_DATADIR,
60
62
  PROP_IMAGEDIR,
61
63
  PROP_CONFIGDIR,
62
64
};
128
130
    case PROP_WINDOW_MANAGER:
129
131
      g_value_set_object (value, global->wm);
130
132
      break;
 
133
    case PROP_DATADIR:
 
134
      g_value_set_string (value, global->datadir);
 
135
      break;
131
136
    case PROP_IMAGEDIR:
132
137
      g_value_set_string (value, global->imagedir);
133
138
      break;
149
154
 
150
155
  if (!datadir)
151
156
    datadir = GNOME_SHELL_DATADIR;
 
157
  global->datadir = datadir;
152
158
 
153
159
  /* We make sure imagedir ends with a '/', since the JS won't have
154
160
   * access to g_build_filename() and so will end up just
255
261
                                                        SHELL_TYPE_WM,
256
262
                                                        G_PARAM_READABLE));
257
263
  g_object_class_install_property (gobject_class,
 
264
                                   PROP_DATADIR,
 
265
                                   g_param_spec_string ("datadir",
 
266
                                                        "Data directory",
 
267
                                                        "Directory containing gnome-shell data files",
 
268
                                                        NULL,
 
269
                                                        G_PARAM_READABLE));
 
270
  g_object_class_install_property (gobject_class,
258
271
                                   PROP_IMAGEDIR,
259
272
                                   g_param_spec_string ("imagedir",
260
273
                                                        "Image directory",
869
882
 
870
883
  return clutter_clone_new (global->root_pixmap);
871
884
}
 
885
 
 
886
/**
 
887
 * shell_global_get_monitors:
 
888
 * @global: the #ShellGlobal
 
889
 *
 
890
 * Gets a list of the bounding boxes of the active screen's monitors.
 
891
 *
 
892
 * Return value: (transfer full) (element-type GdkRectangle): a list
 
893
 * of monitor bounding boxes.
 
894
 */
 
895
GSList *
 
896
shell_global_get_monitors (ShellGlobal *global)
 
897
{
 
898
  MetaScreen *screen = shell_global_get_screen (global);
 
899
  GSList *monitors = NULL;
 
900
  MetaRectangle rect;
 
901
  int i;
 
902
 
 
903
  g_assert (sizeof (MetaRectangle) == sizeof (GdkRectangle) &&
 
904
            G_STRUCT_OFFSET (MetaRectangle, x) == G_STRUCT_OFFSET (GdkRectangle, x) &&
 
905
            G_STRUCT_OFFSET (MetaRectangle, y) == G_STRUCT_OFFSET (GdkRectangle, y) &&
 
906
            G_STRUCT_OFFSET (MetaRectangle, width) == G_STRUCT_OFFSET (GdkRectangle, width) &&
 
907
            G_STRUCT_OFFSET (MetaRectangle, height) == G_STRUCT_OFFSET (GdkRectangle, height));
 
908
 
 
909
  for (i = meta_screen_get_n_monitors (screen) - 1; i >= 0; i--)
 
910
    {
 
911
      meta_screen_get_monitor_geometry (screen, i, &rect);
 
912
      monitors = g_slist_prepend (monitors,
 
913
                                  g_boxed_copy (GDK_TYPE_RECTANGLE, &rect));
 
914
    }
 
915
  return monitors;
 
916
}
 
917
 
 
918
/**
 
919
 * shell_global_get_primary_monitor:
 
920
 * @global: the #ShellGlobal
 
921
 *
 
922
 * Gets the bounding box of the primary monitor (the one that the
 
923
 * panel is on).
 
924
 *
 
925
 * Return value: the bounding box of the primary monitor
 
926
 */
 
927
GdkRectangle *
 
928
shell_global_get_primary_monitor (ShellGlobal  *global)
 
929
{
 
930
  MetaScreen *screen = shell_global_get_screen (global);
 
931
  MetaRectangle rect;
 
932
 
 
933
  g_assert (sizeof (MetaRectangle) == sizeof (GdkRectangle) &&
 
934
            G_STRUCT_OFFSET (MetaRectangle, x) == G_STRUCT_OFFSET (GdkRectangle, x) &&
 
935
            G_STRUCT_OFFSET (MetaRectangle, y) == G_STRUCT_OFFSET (GdkRectangle, y) &&
 
936
            G_STRUCT_OFFSET (MetaRectangle, width) == G_STRUCT_OFFSET (GdkRectangle, width) &&
 
937
            G_STRUCT_OFFSET (MetaRectangle, height) == G_STRUCT_OFFSET (GdkRectangle, height));
 
938
 
 
939
  meta_screen_get_monitor_geometry (screen, 0, &rect);
 
940
  return g_boxed_copy (GDK_TYPE_RECTANGLE, &rect);
 
941
}
 
942
 
 
943
/**
 
944
 * shell_global_get_focus_monitor:
 
945
 * @global: the #ShellGlobal
 
946
 *
 
947
 * Gets the bounding box of the monitor containing the window that
 
948
 * currently contains the keyboard focus.
 
949
 *
 
950
 * Return value: the bounding box of the focus monitor
 
951
 */
 
952
GdkRectangle *
 
953
shell_global_get_focus_monitor (ShellGlobal  *global)
 
954
{
 
955
  MetaScreen *screen = shell_global_get_screen (global);
 
956
  MetaDisplay *display = meta_screen_get_display (screen);
 
957
  MetaWindow *focus = meta_display_get_focus_window (display);
 
958
  MetaRectangle rect, wrect;
 
959
  int nmonitors, i;
 
960
 
 
961
  if (focus)
 
962
    {
 
963
      meta_window_get_outer_rect (focus, &wrect);
 
964
      nmonitors = meta_screen_get_n_monitors (screen);
 
965
 
 
966
      /* Find the monitor that the top-left corner of @focus is on. */
 
967
      for (i = 0; i < nmonitors; i++)
 
968
        {
 
969
          meta_screen_get_monitor_geometry (screen, i, &rect);
 
970
 
 
971
          if (rect.x < wrect.x && rect.y < wrect.y &&
 
972
              rect.x + rect.width > wrect.x &&
 
973
              rect.y + rect.height > wrect.y)
 
974
            return g_boxed_copy (GDK_TYPE_RECTANGLE, &rect);
 
975
        }
 
976
    }
 
977
 
 
978
  meta_screen_get_monitor_geometry (screen, 0, &rect);
 
979
  return g_boxed_copy (GDK_TYPE_RECTANGLE, &rect);
 
980
}
 
981
 
 
982
/**
 
983
 * shell_global_get_modifier_keys:
 
984
 * @global: the #ShellGlobal
 
985
 *
 
986
 * Gets the current set of modifier keys that are pressed down;
 
987
 * this is a wrapper around gdk_display_get_pointer() that strips
 
988
 * out any un-declared modifier flags, to make gjs happy; see
 
989
 * https://bugzilla.gnome.org/show_bug.cgi?id=597292.
 
990
 *
 
991
 * Return value: the current modifiers
 
992
 */
 
993
GdkModifierType
 
994
shell_global_get_modifier_keys (ShellGlobal *global)
 
995
{
 
996
  GdkModifierType mods;
 
997
 
 
998
  gdk_display_get_pointer (gdk_display_get_default (), NULL, NULL, NULL, &mods);
 
999
  return mods & GDK_MODIFIER_MASK;
 
1000
}
 
1001
 
 
1002
/**
 
1003
 * shell_get_event_state:
 
1004
 * @event: a #ClutterEvent
 
1005
 *
 
1006
 * Gets the current state of the event (the set of modifier keys that
 
1007
 * are pressed down). Thhis is a wrapper around
 
1008
 * clutter_event_get_state() that strips out any un-declared modifier
 
1009
 * flags, to make gjs happy; see
 
1010
 * https://bugzilla.gnome.org/show_bug.cgi?id=597292.
 
1011
 *
 
1012
 * Return value: the state from the event
 
1013
 */
 
1014
ClutterModifierType
 
1015
shell_get_event_state (ClutterEvent *event)
 
1016
{
 
1017
  ClutterModifierType state = clutter_event_get_state (event);
 
1018
  return state & CLUTTER_MODIFIER_MASK;
 
1019
}