コード例 #1
0
static void
test_window (void)
{
	GSWindow   *window;
	gboolean    lock_active;
	gboolean    user_switch_enabled;
	GdkDisplay *display;
#if GTK_CHECK_VERSION (3, 22, 0)
	GdkMonitor *monitor;
#else
	GdkScreen  *screen;
	int         monitor;
#endif

	lock_active = TRUE;
	user_switch_enabled = TRUE;
	display = gdk_display_get_default ();
#if GTK_CHECK_VERSION (3, 22, 0)
	monitor = gdk_display_get_primary_monitor (display);
#else
	screen = gdk_display_get_default_screen (display);
	monitor = gdk_screen_get_primary_monitor (screen);
#endif

	window = gs_window_new (display, monitor, lock_active);

	gs_window_set_user_switch_enabled (window, user_switch_enabled);

	connect_window_signals (window);

	gs_window_show (window);
}
コード例 #2
0
ファイル: GSLinuxDialog.cpp プロジェクト: Alchemistxxd/pcsx2
bool BigEnough()
{
#if GTK3_MONITOR_API
	GdkMonitor *monitor = gdk_display_get_primary_monitor(gdk_display_get_default());
	// int scale = gdk_monitor_get_scale_factor(monitor);
	GdkRectangle my_geometry;
	gdk_monitor_get_geometry(monitor, &my_geometry);
	return my_geometry.height > 1000;
#else
	return (gdk_screen_get_height(gdk_screen_get_default()) > 1000);
#endif
}
コード例 #3
0
ファイル: animated-resizing.c プロジェクト: endlessm/gtk
int
main(int argc, char **argv)
{
  GError *error = NULL;
  GdkMonitor *monitor;
  GdkRectangle monitor_bounds;

  GOptionContext *context = g_option_context_new (NULL);
  g_option_context_add_main_entries (context, options, NULL);
  frame_stats_add_options (g_option_context_get_main_group (context));
  g_option_context_add_group (context,
                              gtk_get_option_group (TRUE));

  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_printerr ("Option parsing failed: %s\n", error->message);
      return 1;
    }

  g_print ("# Load factor: %g\n",
           load_factor);
  g_print ("# Resizing?: %s\n",
           cb_no_resize ? "no" : "yes");

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  frame_stats_ensure (GTK_WINDOW (window));

  gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
  gtk_window_set_gravity (GTK_WINDOW (window), GDK_GRAVITY_CENTER);
  gtk_widget_set_app_paintable (window, TRUE);

  g_signal_connect (window, "draw",
                    G_CALLBACK (on_window_draw), NULL);
  g_signal_connect (window, "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

  g_signal_connect (window, "map-event",
                    G_CALLBACK (on_map_event), NULL);
  on_frame (0.);

  monitor = gdk_display_get_primary_monitor (gtk_widget_get_display (window));
  gdk_monitor_get_geometry (monitor, &monitor_bounds);

  gtk_window_move (GTK_WINDOW (window),
                   monitor_bounds.x + (monitor_bounds.width - window_width) / 2,
                   monitor_bounds.y + (monitor_bounds.height - window_height) / 2);

  gtk_widget_show (window);

  gtk_main ();

  return 0;
}
コード例 #4
0
ファイル: utilsgtk.cpp プロジェクト: slunski/wxWidgets
void wxDisplaySizeMM( int *width, int *height )
{
#ifdef __WXGTK4__
    GdkMonitor* monitor = gdk_display_get_primary_monitor(gdk_display_get_default());
    if (width) *width = gdk_monitor_get_width_mm(monitor);
    if (height) *height = gdk_monitor_get_height_mm(monitor);
#else
    wxGCC_WARNING_SUPPRESS(deprecated-declarations)
    if (width) *width = gdk_screen_width_mm();
    if (height) *height = gdk_screen_height_mm();
    wxGCC_WARNING_RESTORE()
#endif
}
コード例 #5
0
ファイル: utilsgtk.cpp プロジェクト: slunski/wxWidgets
void wxDisplaySize( int *width, int *height )
{
#ifdef __WXGTK4__
    GdkMonitor* monitor = gdk_display_get_primary_monitor(gdk_display_get_default());
    GdkRectangle rect;
    gdk_monitor_get_geometry(monitor, &rect);
    if (width) *width = rect.width;
    if (height) *height = rect.height;
#else
    wxGCC_WARNING_SUPPRESS(deprecated-declarations)
    if (width) *width = gdk_screen_width();
    if (height) *height = gdk_screen_height();
    wxGCC_WARNING_RESTORE()
#endif
}
コード例 #6
0
/**
 * gdk_screen_get_primary_monitor:
 * @screen: a #GdkScreen.
 *
 * Gets the primary monitor for @screen.  The primary monitor
 * is considered the monitor where the “main desktop” lives.
 * While normal application windows typically allow the window
 * manager to place the windows, specialized desktop applications
 * such as panels should place themselves on the primary monitor.
 *
 * If no primary monitor is configured by the user, the return value
 * will be 0, defaulting to the first monitor.
 *
 * Returns: An integer index for the primary monitor, or 0 if none is configured.
 *
 * Since: 2.20
 */
gint
gdk_screen_get_primary_monitor (GdkScreen *screen)
{
    GdkDisplay *display;
    GdkMonitor *primary;

    g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);

    display = gdk_screen_get_display (screen);
    primary = gdk_display_get_primary_monitor (display);
    if (primary)
        return get_monitor_num (primary);

    return 0;
}
コード例 #7
0
static void
test_window (void)
{
	GSWindow   *window;
	gboolean    lock_active;
	gboolean    user_switch_enabled;
	GdkDisplay *display;
	GdkMonitor *monitor;

	lock_active = TRUE;
	user_switch_enabled = TRUE;
	display = gdk_display_get_default ();
	monitor = gdk_display_get_primary_monitor (display);

	window = gs_window_new (monitor, lock_active);

	gs_window_set_user_switch_enabled (window, user_switch_enabled);

	connect_window_signals (window);

	gs_window_show (window);
}
コード例 #8
0
ファイル: tools.c プロジェクト: Buzztrax/buzztrax
/**
 * bt_gtk_workarea_size:
 * @max_width: destination for the width or %NULL
 * @max_height: destination for the heigth or %NULL
 *
 * Gets the potitial max size the window could occupy. This can be used to
 * hint the content size for #GtkScrelledWindow.
 */
void
bt_gtk_workarea_size (gint * max_width, gint * max_height)
{
#if GTK_CHECK_VERSION (3, 22, 0)
  GdkRectangle area;
  gdk_monitor_get_workarea (
      gdk_display_get_primary_monitor (gdk_display_get_default ()),
      &area);
  if (max_width)
    *max_width = area.width;
  if (max_height)
    *max_height = area.height;
#else
  GdkScreen *screen = gdk_screen_get_default ();
  /* TODO(ensonjc): these constances below are arbitrary
   * look at http://standards.freedesktop.org/wm-spec/1.3/ar01s05.html#id2523368
   * search for _NET_WM_STRUT_PARTIAL
   */
  if (max_width)
    *max_width = gdk_screen_get_width (screen) - 16;
  if (max_height)
    *max_height = gdk_screen_get_height (screen) - 80;
#endif
}
コード例 #9
0
ファイル: gimpsessioninfo.c プロジェクト: jiapei100/gimp
/**
 * gimp_session_info_read_geometry:
 * @info:  A #GimpSessionInfo
 * @cevent A #GdkEventConfigure. If set, use the size from here
 *         instead of from the window allocation.
 *
 * Read geometry related information from the associated widget.
 **/
void
gimp_session_info_read_geometry (GimpSessionInfo   *info,
                                 GdkEventConfigure *cevent)
{
  GdkWindow  *window;
  GdkDisplay *display;

  g_return_if_fail (GIMP_IS_SESSION_INFO (info));
  g_return_if_fail (GTK_IS_WINDOW (info->p->widget));

  window  = gtk_widget_get_window (info->p->widget);
  display = gtk_widget_get_display (info->p->widget);

  if (window)
    {
      gint          x, y;
      GdkMonitor   *monitor;
      GdkRectangle  geometry;

      gtk_window_get_position (GTK_WINDOW (info->p->widget), &x, &y);

      /* Don't write negative values to the sessionrc, they are
       * interpreted as relative to the right, respective bottom edge
       * of the display.
       */
      info->p->x = MAX (0, x);
      info->p->y = MAX (0, y);

      monitor = gdk_display_get_monitor_at_point (display,
                                                  info->p->x, info->p->y);
      gdk_monitor_get_geometry (monitor, &geometry);

      /* Always store window coordinates relative to the monitor */
      info->p->x -= geometry.x;
      info->p->y -= geometry.y;

      if (gimp_session_info_get_remember_size (info))
        {
          gtk_window_get_size (GTK_WINDOW (info->p->widget),
                               &info->p->width, &info->p->height);
        }
      else
        {
          info->p->width  = 0;
          info->p->height = 0;
        }

      info->p->monitor = DEFAULT_MONITOR;

      if (monitor != gdk_display_get_primary_monitor (display))
        info->p->monitor = monitor;
    }

  info->p->open = FALSE;

  if (gimp_session_info_get_remember_if_open (info))
    {
      GimpDialogVisibilityState visibility;

      visibility =
        GPOINTER_TO_INT (g_object_get_data (G_OBJECT (info->p->widget),
                                            GIMP_DIALOG_VISIBILITY_KEY));

      switch (visibility)
        {
        case GIMP_DIALOG_VISIBILITY_UNKNOWN:
          info->p->open = gtk_widget_get_visible (info->p->widget);
          break;

        case GIMP_DIALOG_VISIBILITY_INVISIBLE:
          info->p->open = FALSE;
          break;

        case GIMP_DIALOG_VISIBILITY_HIDDEN:
        case GIMP_DIALOG_VISIBILITY_VISIBLE:
          /* Even if a dialog is hidden (with Windows->Hide docks) it
           * is still considered open. It will be restored the next
           * time GIMP starts
           */
          info->p->open = TRUE;
          break;
        }
    }
}
コード例 #10
0
ファイル: gimpsessioninfo.c プロジェクト: jiapei100/gimp
/**
 * gimp_session_info_apply_geometry:
 * @info:
 * @monitor:
 * @current_monitor:
 *
 * Apply the geometry stored in the session info object to the
 * associated widget.
 **/
void
gimp_session_info_apply_geometry (GimpSessionInfo *info,
                                  GdkMonitor      *current_monitor,
                                  gboolean         apply_stored_monitor)
{
  GdkMonitor     *monitor;
  GdkRectangle    rect;
  GdkRectangle    work_rect;
  GdkGravity      gravity;
  GdkWindowHints  hints;
  gint            width;
  gint            height;

  g_return_if_fail (GIMP_IS_SESSION_INFO (info));
  g_return_if_fail (GTK_IS_WINDOW (info->p->widget));
  g_return_if_fail (GDK_IS_MONITOR (current_monitor));

  monitor = current_monitor;

  if (apply_stored_monitor)
    {
      GdkDisplay *display = gdk_monitor_get_display (current_monitor);
      gint        n_monitors;

      n_monitors = gdk_display_get_n_monitors (display);

      if (info->p->monitor                  != DEFAULT_MONITOR &&
          monitor_number (info->p->monitor) <  n_monitors)
        {
          monitor = info->p->monitor;
        }
      else
        {
          monitor = gdk_display_get_primary_monitor (display);
        }
    }

  gdk_monitor_get_geometry (monitor, &rect);
  gdk_monitor_get_workarea (monitor, &work_rect);

  info->p->x += rect.x;
  info->p->y += rect.y;

  if (gimp_session_info_get_remember_size (info) &&
      info->p->width  > 0 &&
      info->p->height > 0)
    {
      width  = info->p->width;
      height = info->p->height;
    }
  else
    {
      GtkRequisition requisition;

      gtk_widget_get_preferred_size (info->p->widget, NULL, &requisition);

      width  = requisition.width;
      height = requisition.height;
    }

  info->p->x = CLAMP (info->p->x,
                      work_rect.x,
                      work_rect.x + work_rect.width  - width);
  info->p->y = CLAMP (info->p->y,
                      work_rect.y,
                      work_rect.y + work_rect.height - height);

  if (gimp_session_info_get_remember_size (info) &&
      info->p->width  > 0 &&
      info->p->height > 0)
    {
      /*  This used to call gtk_window_set_default_size() which worked
       *  fine in gtk2 and should continue to work, but doesn't for
       *  dock windows. gtk_window_resize() seems to work fine for all
       *  windows. Leave this comment here until we figured what's
       *  going on...
       *
       *  XXX If we end up updating this code, also do the same to the
       *  gtk_window_resize() call in gimp_session_info_dialog_show()
       *  signal handler.
       */
#if 1
      gtk_window_resize (GTK_WINDOW (info->p->widget),
                         info->p->width, info->p->height);
#else
      gtk_window_set_default_size (GTK_WINDOW (info->p->widget),
                                   info->p->width, info->p->height);
#endif
   }

  gtk_window_get_size (GTK_WINDOW (info->p->widget), &width, &height);

  gravity = GDK_GRAVITY_NORTH_WEST;

  if (info->p->right_align && info->p->bottom_align)
    {
      gravity = GDK_GRAVITY_SOUTH_EAST;
    }
  else if (info->p->right_align)
    {
      gravity = GDK_GRAVITY_NORTH_EAST;
    }
  else if (info->p->bottom_align)
    {
      gravity = GDK_GRAVITY_SOUTH_WEST;
    }

  if (gravity == GDK_GRAVITY_SOUTH_EAST ||
      gravity == GDK_GRAVITY_NORTH_EAST)
    info->p->x = work_rect.x + work_rect.width - width;

  if (gravity == GDK_GRAVITY_SOUTH_WEST ||
      gravity == GDK_GRAVITY_SOUTH_EAST)
    info->p->y = work_rect.y + work_rect.height - height;

  gtk_window_set_gravity (GTK_WINDOW (info->p->widget), gravity);
  gtk_window_move (GTK_WINDOW (info->p->widget),
                   info->p->x, info->p->y);

  hints = GDK_HINT_USER_POS;
  if (gimp_session_info_get_remember_size (info))
    hints |= GDK_HINT_USER_SIZE;

  gtk_window_set_geometry_hints (GTK_WINDOW (info->p->widget),
                                 NULL, NULL, hints);

  /*  Window managers and windowing systems suck. They have their own
   *  ideas about WM standards and when it's appropriate to honor
   *  user/application-set window positions and when not. Therefore,
   *  use brute force and "manually" position dialogs whenever they
   *  are shown. This is important especially for transient dialogs,
   *  because window managers behave even "smarter" then...
   */
  if (GTK_IS_WINDOW (info->p->widget))
    g_signal_connect (info->p->widget, "show",
                      G_CALLBACK (gimp_session_info_dialog_show),
                      info);
}