Exemplo n.º 1
0
void
gimp_popup_show (GimpPopup *popup,
                 GtkWidget *widget)
{
    GdkScreen      *screen;
    GtkRequisition  requisition;
    GtkAllocation   allocation;
    GdkRectangle    rect;
    gint            monitor;
    gint            orig_x;
    gint            orig_y;
    gint            x;
    gint            y;

    g_return_if_fail (GIMP_IS_POPUP (popup));
    g_return_if_fail (GTK_IS_WIDGET (widget));

    gtk_widget_size_request (GTK_WIDGET (popup), &requisition);

    gtk_widget_get_allocation (widget, &allocation);
    gdk_window_get_origin (gtk_widget_get_window (widget), &orig_x, &orig_y);

    if (! gtk_widget_get_has_window (widget))
    {
        orig_x += allocation.x;
        orig_y += allocation.y;
    }

    screen = gtk_widget_get_screen (widget);

    monitor = gdk_screen_get_monitor_at_point (screen, orig_x, orig_y);
    gdk_screen_get_monitor_workarea (screen, monitor, &rect);

    if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
    {
        x = orig_x + allocation.width - requisition.width;

        if (x < rect.x)
            x -= allocation.width - requisition.width;
    }
    else
    {
        x = orig_x;

        if (x + requisition.width > rect.x + rect.width)
            x += allocation.width - requisition.width;
    }

    y = orig_y + allocation.height;

    if (y + requisition.height > rect.y + rect.height)
        y = orig_y - requisition.height;

    gtk_window_set_screen (GTK_WINDOW (popup), screen);
    gtk_window_set_transient_for (GTK_WINDOW (popup),
                                  GTK_WINDOW (gtk_widget_get_toplevel (widget)));

    gtk_window_move (GTK_WINDOW (popup), x, y);
    gtk_widget_show (GTK_WIDGET (popup));
}
Exemplo n.º 2
0
void Ctrl::GetWorkArea(Array<Rect>& rc)
{
	GuiLock __;
	GdkScreen *s = gdk_screen_get_default();
	int n = gdk_screen_get_n_monitors(s);
	rc.Clear();
	Vector<int> netwa;
	for(int i = 0; i < n; i++) {
		GdkRectangle rr;
		Rect r;
#if GTK_CHECK_VERSION (3, 3, 5) // U++ does not work with gtk3 yet, but be prepared
		gdk_screen_get_monitor_workarea(s, i, &rr);
		r = RectC(r.x, r.y, r.width, r.height);
#else
		gdk_screen_get_monitor_geometry (s, i, &rr);
		r = RectC(rr.x, rr.y, rr.width, rr.height);
	#ifdef GDK_WINDOWING_X11
		if(i == 0)
			netwa = GetPropertyInts(gdk_screen_get_root_window(gdk_screen_get_default()),
			                        "_NET_WORKAREA");
		if(netwa.GetCount())
			r = r & RectC(netwa[0], netwa[1], netwa[2], netwa[3]);
	#endif
#endif
		rc.Add(r);
	}
}
Exemplo n.º 3
0
static inline void
wx_gdk_screen_get_monitor_workarea(GdkScreen* screen, int monitor, GdkRectangle* dest)
{
#if GTK_CHECK_VERSION(3,4,0)
    if (gtk_check_version(3,4,0) == NULL)
        gdk_screen_get_monitor_workarea(screen, monitor, dest);
    else
#endif
    {
        gdk_screen_get_monitor_geometry(screen, monitor, dest);
#ifdef GDK_WINDOWING_X11
#ifdef __WXGTK3__
        if (GDK_IS_X11_SCREEN(screen))
#endif
        {
            GdkRectangle rect = { 0 };
            wxGetWorkAreaX11(GDK_SCREEN_XSCREEN(screen),
                             rect.x, rect.y, rect.width, rect.height);
            // in case _NET_WORKAREA result is too large
            if (rect.width && rect.height)
                gdk_rectangle_intersect(dest, &rect, dest);
        }
#endif // GDK_WINDOWING_X11
    }
}
static void
get_screenshot_async (CcBackgroundPanel *panel)
{
  CcBackgroundPanelPrivate *priv = panel->priv;
  gchar *path, *tmpname;
  const gchar *method_name;
  GVariant *method_params;
  GtkWidget *widget;
  ScreenshotData *data;
  int primary;

  data = g_new0 (ScreenshotData, 1);
  data->panel = panel;

  widget = WID ("background-desktop-drawingarea");
  primary = gdk_screen_get_primary_monitor (gtk_widget_get_screen (widget));
  gdk_screen_get_monitor_geometry (gtk_widget_get_screen (widget), primary, &data->monitor_rect);
  gdk_screen_get_monitor_workarea (gtk_widget_get_screen (widget), primary, &data->workarea_rect);
  if (calculate_contiguous_workarea (data)) {
    g_debug ("Capturing only a portion of the screen");
  } else {
    g_debug ("Capturing the whole monitor");
    data->whole_monitor = TRUE;
    data->capture_rect = data->monitor_rect;
  }

  g_debug ("Trying to capture rectangle %dx%d (at %d,%d)",
           data->capture_rect.width, data->capture_rect.height, data->capture_rect.x, data->capture_rect.y);

  path = g_build_filename (g_get_user_cache_dir (), "gnome-control-center", NULL);
  g_mkdir_with_parents (path, USER_DIR_MODE);

  tmpname = g_strdup_printf ("scr-%d.png", g_random_int ());
  g_free (panel->priv->screenshot_path);
  panel->priv->screenshot_path = g_build_filename (path, tmpname, NULL);
  g_free (path);
  g_free (tmpname);

  method_name = "ScreenshotArea";
  method_params = g_variant_new ("(iiiibs)",
                                 data->capture_rect.x, data->capture_rect.y,
                                 data->capture_rect.width, data->capture_rect.height,
                                 FALSE, /* flash */
                                 panel->priv->screenshot_path);

  g_dbus_connection_call (panel->priv->connection,
                          "org.gnome.Shell.Screenshot",
                          "/org/gnome/Shell/Screenshot",
                          "org.gnome.Shell.Screenshot",
                          method_name,
                          method_params,
                          NULL,
                          G_DBUS_CALL_FLAGS_NONE,
                          -1,
                          priv->capture_cancellable,
                          on_screenshot_finished,
                          data);
}
/* adapted from gtk/gtkmenubutton.c */
static void
menu_position_func (GtkMenu       *menu,
		    gint          *x,
		    gint          *y,
		    gboolean      *push_in,
		    GtkWidget     *widget)
{
	GtkWidget *toplevel;
	GtkRequisition menu_req;
	GdkRectangle monitor;
	gint monitor_num;
	GdkScreen *screen;
	GdkWindow *window;
	GtkAllocation allocation;

	/* Set the dropdown menu hint on the toplevel, so the WM can omit the top side
	 * of the shadows.
	 */
	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
	gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);

	window = gtk_widget_get_window (widget);
	screen = gtk_widget_get_screen (GTK_WIDGET (menu));
	monitor_num = gdk_screen_get_monitor_at_window (screen, window);
	if (monitor_num < 0) {
		monitor_num = 0;
	}

	gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
	gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_req, NULL);
	gtk_widget_get_allocation (widget, &allocation);
	gdk_window_get_origin (window, x, y);

	*x += allocation.x;
	*y += allocation.y;

	if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) {
		*x -= MAX (menu_req.width - allocation.width, 0);
	} else {
		*x += MAX (allocation.width - menu_req.width, 0);
	}

	if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height) {
		*y += allocation.height;
	} else if ((*y - menu_req.height) >= monitor.y) {
		*y -= menu_req.height;
	} else if (monitor.y + monitor.height - (*y + allocation.height) > *y) {
		*y += allocation.height;
	} else {
		*y -= menu_req.height;
	}

	*push_in = FALSE;
}
Exemplo n.º 6
0
/*
 * Figure out the size of the working area and resize the window to fit into
 * that.
 */
static void
set_window_geometry(GtkWindow *window, GtkWidget *widget)
{
	GdkScreen	*screen;
	GdkRectangle	 rect;

	if ((screen = gdk_screen_get_default()) == NULL)
		errx(1, "gdk_screen_get_default");

	gdk_screen_get_monitor_workarea(screen, 0, &rect);

	gtk_window_set_default_size(window, rect.width, rect.height);
	gtk_widget_set_size_request(widget, rect.width, rect.height);
	gtk_window_move(window, rect.x, rect.y);
}
Exemplo n.º 7
0
FloatRect screenAvailableRect(Widget* widget)
{
    GtkWidget* container = widget ? GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()) : 0;
    if (container && !gtk_widget_get_realized(container))
        return screenRect(widget);

    GdkScreen* screen = container ? getScreen(container) : gdk_screen_get_default();
    if (!screen)
        return FloatRect();

    gint monitor = container ? gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(container)) : 0;

    GdkRectangle workArea;
    gdk_screen_get_monitor_workarea(screen, monitor, &workArea);

    return FloatRect(workArea.x, workArea.y, workArea.width, workArea.height);

}
static void
position_window (CcRRLabeler  *labeler,
		 GtkWidget       *window,
		 int              x,
		 int              y)
{
	GdkRectangle    workarea;
	GdkRectangle    monitor;
	int             monitor_num;

	monitor_num = gdk_screen_get_monitor_at_point (labeler->priv->screen, x, y);
	gdk_screen_get_monitor_workarea (labeler->priv->screen, monitor_num, &workarea);
	gdk_screen_get_monitor_geometry (labeler->priv->screen,
                                         monitor_num,
                                         &monitor);
	gdk_rectangle_intersect (&monitor, &workarea, &workarea);

	gtk_window_move (GTK_WINDOW (window), workarea.x, workarea.y);
}
Exemplo n.º 9
0
void uiWindowCenter(uiWindow *w)
{
	gint x, y;
	GtkAllocation winalloc;
	GdkWindow *gdkwin;
	GdkScreen *screen;
	GdkRectangle workarea;

	gtk_widget_get_allocation(w->widget, &winalloc);
	gdkwin = gtk_widget_get_window(w->widget);
	screen = gdk_window_get_screen(gdkwin);
	gdk_screen_get_monitor_workarea(screen,
		gdk_screen_get_monitor_at_window(screen, gdkwin),
		&workarea);

	x = (workarea.width - winalloc.width) / 2;
	y = (workarea.height - winalloc.height) / 2;
	// TODO move up slightly? see what Mutter or GNOME Shell or GNOME Terminal do(es)?
	uiWindowSetPosition(w, x, y);
}
Exemplo n.º 10
0
void wxClientDisplayRect(int* x, int* y, int* width, int* height)
{
#if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
    GdkRectangle rect = { 0, 0, 672, 396 };
#else
    GdkRectangle rect;
    GdkWindow* window = gtk_widget_get_window(wxGetRootWindow());
    GdkScreen* screen = gdk_window_get_screen(window);
    int monitor = gdk_screen_get_monitor_at_window(screen, window);
    gdk_screen_get_monitor_workarea(screen, monitor, &rect);
#endif
    if (x)
        *x = rect.x;
    if (y)
        *y = rect.y;
    if (width)
        *width = rect.width;
    if (height)
        *height = rect.height;
}
Exemplo n.º 11
0
/**
 * cheese_flash_fire:
 * @flash: a #CheeseFlash
 *
 * Fire the flash.
 */
void
cheese_flash_fire (CheeseFlash *flash)
{
  CheeseFlashPrivate *flash_priv;
  GtkWidget          *parent;
  GdkScreen          *screen;
  GdkRectangle        rect, work_rect;
  int                 monitor;
  GtkWindow *flash_window;

  g_return_if_fail (CHEESE_IS_FLASH (flash));

  flash_priv = flash->priv;

  g_return_if_fail (flash_priv->parent != NULL);

  flash_window = GTK_WINDOW (flash);

  if (flash_priv->flash_timeout_tag > 0)
    g_source_remove (flash_priv->flash_timeout_tag);
  if (flash_priv->fade_timeout_tag > 0)
    g_source_remove (flash_priv->fade_timeout_tag);

  parent  = gtk_widget_get_toplevel (flash_priv->parent);
  screen  = gtk_widget_get_screen (parent);
  monitor = gdk_screen_get_monitor_at_window (screen,
					      gtk_widget_get_window (parent));

  gdk_screen_get_monitor_geometry (screen, monitor, &rect);
  gdk_screen_get_monitor_workarea (screen, monitor, &work_rect);
  gdk_rectangle_intersect (&work_rect, &rect, &rect);

  gtk_window_set_transient_for (GTK_WINDOW (flash_window), GTK_WINDOW (parent));
  gtk_window_resize (flash_window, rect.width, rect.height);
  gtk_window_move (flash_window, rect.x, rect.y);

  gtk_window_set_opacity (flash_window, 1);
  gtk_widget_show_all (GTK_WIDGET (flash_window));
  flash_priv->flash_timeout_tag = g_timeout_add (FLASH_DURATION, cheese_flash_start_fade, (gpointer) flash);
}
Exemplo n.º 12
0
static void
popup_position_func (GtkMenu   *menu,
                     gint      *x,
                     gint      *y,
                     gboolean  *push_in,
                     gpointer   user_data)
{
  GtkWidget *widget;
  GtkRequisition req;
  gint root_x, root_y;
  GdkScreen *screen;
  GdkWindow *window;
  GdkRectangle monitor;
  gint monitor_num;

  widget = GTK_WIDGET (user_data);
  g_return_if_fail (gtk_widget_get_realized (widget));
  window = gtk_widget_get_window (widget);

  screen = gtk_widget_get_screen (widget);
  monitor_num = gdk_screen_get_monitor_at_window (screen, window);
  if (monitor_num < 0)
    monitor_num = 0;
  gtk_menu_set_monitor (menu, monitor_num);

  gdk_window_get_origin (window, &root_x, &root_y);
  gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);

  /* Put corner of menu centered on swatch */
  *x = root_x + gtk_widget_get_allocated_width (widget) / 2;
  *y = root_y + gtk_widget_get_allocated_height (widget) / 2;

  /* Ensure sanity */
  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
  *x = CLAMP (*x, monitor.x, MAX (monitor.x, monitor.width - req.width));
  *y = CLAMP (*y, monitor.y, MAX (monitor.y, monitor.height - req.height));
}
Exemplo n.º 13
0
int
main (int argc, char **argv)
{
  GtkWidget *window;
  GdkScreen *screen;
  int monitor;
  GdkRectangle rect;
  GError *error = NULL;
  char *font = NULL;
  GtkApplication *application;
  guint status;
  GOptionEntry goptions[] =
  {
    { "font", 0, 0, G_OPTION_ARG_STRING, &font,
      N_("Font to start with; ex: 'Serif 27'"), N_("FONT") },
    { "version", 0, G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG, 
      G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
    { NULL }
  };

  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

#ifdef HAVE_GCONF
  /* GConf uses ORBit2 which need GThread. See bug #565516 */
  g_thread_init (NULL);
#endif

  /* Set programme name explicitly (see bug #653115) */
  g_set_prgname("gucharmap");

  if (!gtk_init_with_args (&argc, &argv, NULL, goptions, GETTEXT_PACKAGE, &error))
    {
      g_printerr ("%s\n", error->message);
      g_error_free (error);

      exit (1);
    }

  g_set_application_name (_("Character Map"));
  gtk_window_set_default_icon_name (GUCHARMAP_ICON_NAME);

  application = gtk_application_new ("org.gnome.Charmap",
                                     G_APPLICATION_NON_UNIQUE);
  g_signal_connect (application, "startup", G_CALLBACK (startup_cb), NULL);
  g_signal_connect (application, "activate",
                    G_CALLBACK (gucharmap_activate), NULL);

  g_application_register (G_APPLICATION (application), NULL, NULL);

  window = gucharmap_window_new (application);

  screen = gtk_window_get_screen (GTK_WINDOW (window));
  monitor = gdk_screen_get_monitor_at_point (screen, 0, 0);
#if GTK_CHECK_VERSION (3, 3, 5)
  gdk_screen_get_monitor_workarea (screen, monitor, &rect);
#else
  gdk_screen_get_monitor_geometry (screen, monitor, &rect);
#endif
  gtk_window_set_default_size (GTK_WINDOW (window), rect.width * 9/16, rect.height * 9/16);

  if (font)
    {
      gucharmap_window_set_font (GUCHARMAP_WINDOW (window), font);
      g_free (font);
    }

  gtk_window_present (GTK_WINDOW (window));

  status = g_application_run (G_APPLICATION (application), argc, argv);
  g_object_unref (application);

  return status;
}
static void
on_screenshot_finished (GObject *source,
                        GAsyncResult *res,
                        gpointer user_data)
{
  CcBackgroundPanel *panel = user_data;
  CcBackgroundPanelPrivate *priv = panel->priv;
  GError *error;
  GdkRectangle rect;
  GtkWidget *widget;
  GdkPixbuf *pixbuf;
  cairo_surface_t *surface;
  cairo_t *cr;
  int width;
  int height;

  error = NULL;
  g_dbus_connection_call_finish (panel->priv->connection,
                                 res,
                                 &error);

  if (error != NULL) {
    g_debug ("Unable to get screenshot: %s",
             error->message);
    g_error_free (error);
    /* fallback? */
    goto out;
  }

  pixbuf = gdk_pixbuf_new_from_file (panel->priv->screenshot_path, &error);
  if (error != NULL)
    {
      g_debug ("Unable to use GNOME Shell's builtin screenshot interface: %s",
               error->message);
      g_error_free (error);
      goto out;
    }

  width = gdk_pixbuf_get_width (pixbuf);
  height = gdk_pixbuf_get_height (pixbuf);
  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                        width, height);
  cr = cairo_create (surface);
  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_paint (cr);
  g_object_unref (pixbuf);

  /* clear the workarea */
   widget = WID ("background-desktop-drawingarea");
  gdk_screen_get_monitor_workarea (gtk_widget_get_screen (widget), 0, &rect);

  cairo_save (cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
  cairo_fill (cr);
  cairo_restore (cr);

  g_clear_object (&panel->priv->display_screenshot);
  panel->priv->display_screenshot = gdk_pixbuf_get_from_surface (surface,
                                                                 0, 0,
                                                                 width,
                                                                 height);
  /* remove the temporary file created by the shell */
  g_unlink (panel->priv->screenshot_path);
  g_free (priv->screenshot_path);
  priv->screenshot_path = NULL;

  cairo_destroy (cr);
  cairo_surface_destroy (surface);

 out:
  update_display_preview (panel);
}
Exemplo n.º 15
0
static void
gtk_tooltip_position (GtkTooltip *tooltip,
		      GdkDisplay *display,
		      GtkWidget  *new_tooltip_widget)
{
  gint x, y, width, height;
  GdkScreen *screen;
  gint monitor_num;
  GdkRectangle monitor;
  guint cursor_size;
  GdkRectangle bounds;

#define MAX_DISTANCE 32

  gtk_widget_realize (GTK_WIDGET (tooltip->current_window));

  tooltip->tooltip_widget = new_tooltip_widget;

  screen = gtk_widget_get_screen (new_tooltip_widget);

  width = gtk_widget_get_allocated_width (GTK_WIDGET (tooltip->current_window));
  height = gtk_widget_get_allocated_height (GTK_WIDGET (tooltip->current_window));

  monitor_num = gdk_screen_get_monitor_at_point (screen,
                                                 tooltip->last_x,
                                                 tooltip->last_y);
  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);

  get_bounding_box (new_tooltip_widget, &bounds);

  /* Position the tooltip */

  cursor_size = gdk_display_get_default_cursor_size (display);

  /* Try below */
  x = bounds.x + bounds.width / 2 - width / 2;
  y = bounds.y + bounds.height + 4;

  if (y + height <= monitor.y + monitor.height)
    {
      if (tooltip->keyboard_mode_enabled)
        goto found;

      if (y <= tooltip->last_y + cursor_size + MAX_DISTANCE)
        {
          if (tooltip->last_x + cursor_size + MAX_DISTANCE < x)
            x = tooltip->last_x + cursor_size + MAX_DISTANCE;
          else if (x + width < tooltip->last_x - MAX_DISTANCE)
            x = tooltip->last_x - MAX_DISTANCE - width;

          goto found;
        }
   }

  /* Try above */
  x = bounds.x + bounds.width / 2 - width / 2;
  y = bounds.y - height - 4;

  if (y >= monitor.y)
    {
      if (tooltip->keyboard_mode_enabled)
        goto found;

      if (y + height >= tooltip->last_y - MAX_DISTANCE)
        {
          if (tooltip->last_x + cursor_size + MAX_DISTANCE < x)
            x = tooltip->last_x + cursor_size + MAX_DISTANCE;
          else if (x + width < tooltip->last_x - MAX_DISTANCE)
            x = tooltip->last_x - MAX_DISTANCE - width;

          goto found;
        }
    }

  /* Try right FIXME: flip on rtl ? */
  x = bounds.x + bounds.width + 4;
  y = bounds.y + bounds.height / 2 - height / 2;

  if (x + width <= monitor.x + monitor.width)
    {
      if (tooltip->keyboard_mode_enabled)
        goto found;

      if (x <= tooltip->last_x + cursor_size + MAX_DISTANCE)
        {
          if (tooltip->last_y + cursor_size + MAX_DISTANCE < y)
            y = tooltip->last_y + cursor_size + MAX_DISTANCE;
          else if (y + height < tooltip->last_y - MAX_DISTANCE)
            y = tooltip->last_y - MAX_DISTANCE - height;

          goto found;
        }
    }

  /* Try left FIXME: flip on rtl ? */
  x = bounds.x - width - 4;
  y = bounds.y + bounds.height / 2 - height / 2;

  if (x >= monitor.x)
    {
      if (tooltip->keyboard_mode_enabled)
        goto found;

      if (x + width >= tooltip->last_x - MAX_DISTANCE)
        {
          if (tooltip->last_y + cursor_size + MAX_DISTANCE < y)
            y = tooltip->last_y + cursor_size + MAX_DISTANCE;
          else if (y + height < tooltip->last_y - MAX_DISTANCE)
            y = tooltip->last_y - MAX_DISTANCE - height;

          goto found;
        }
    }

   /* Fallback */
  if (tooltip->keyboard_mode_enabled)
    {
      x = bounds.x + bounds.width / 2 - width / 2;
      y = bounds.y + bounds.height + 4;
    }
  else
    {
      /* At cursor */
      x = tooltip->last_x + cursor_size * 3 / 4;
      y = tooltip->last_y + cursor_size * 3 / 4;
    }

found:
  /* Show it */
  if (tooltip->current_window)
    {
      if (x + width > monitor.x + monitor.width)
        x -= x - (monitor.x + monitor.width) + width;
      else if (x < monitor.x)
        x = monitor.x;

      if (y + height > monitor.y + monitor.height)
        y -= y - (monitor.y + monitor.height) + height;
      else if (y < monitor.y)
        y = monitor.y;

      if (!tooltip->keyboard_mode_enabled)
        {
          /* don't pop up under the pointer */
          if (x <= tooltip->last_x && tooltip->last_x < x + width &&
              y <= tooltip->last_y && tooltip->last_y < y + height)
            y = tooltip->last_y - height - 2;
        }

#ifdef GDK_WINDOWING_WAYLAND
      /* set the transient parent on the tooltip when running with the Wayland
       * backend to allow correct positioning of the tooltip windows */
      if (GDK_IS_WAYLAND_DISPLAY (display))
        {
          GtkWidget *toplevel;

          toplevel = gtk_widget_get_toplevel (tooltip->tooltip_widget);
          if (GTK_IS_WINDOW (toplevel))
            gtk_window_set_transient_for (GTK_WINDOW (tooltip->current_window),
                                          GTK_WINDOW (toplevel));
        }
#endif

      gtk_window_move (GTK_WINDOW (tooltip->current_window), x, y);
      gtk_widget_show (GTK_WIDGET (tooltip->current_window));
    }
}
Exemplo n.º 16
0
static void
menu_position_side_func (GtkMenu       *menu,
                         gint          *x,
                         gint          *y,
                         gboolean      *push_in,
                         GtkMenuButton *menu_button)
{
  GtkMenuButtonPrivate *priv = menu_button->priv;
  GtkAllocation allocation;
  GtkAllocation menu_allocation;
  GtkWidget *widget = GTK_WIDGET (menu_button);
  GdkRectangle monitor;
  gint monitor_num;
  GdkScreen *screen;
  GdkWindow *window;
  GtkAlign align;
  GtkTextDirection direction;

  window = gtk_widget_get_window (widget);

  direction = gtk_widget_get_direction (widget);
  align = gtk_widget_get_valign (GTK_WIDGET (menu));
  screen = gtk_widget_get_screen (GTK_WIDGET (menu));
  monitor_num = gdk_screen_get_monitor_at_window (screen, window);
  if (monitor_num < 0)
    monitor_num = 0;
  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);

  gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (menu_button)), x, y);

  gtk_widget_get_allocation (widget, &allocation);
  gtk_widget_get_allocation (priv->menu, &menu_allocation);

  if ((priv->arrow_type == GTK_ARROW_RIGHT && direction == GTK_TEXT_DIR_LTR) ||
      (priv->arrow_type == GTK_ARROW_LEFT && direction == GTK_TEXT_DIR_RTL))

    {
      if (*x + allocation.width + menu_allocation.width <= monitor.x + monitor.width)
        *x += allocation.width;
      else
        *x -= menu_allocation.width;
    }
  else
    {
      if (*x - menu_allocation.width >= monitor.x)
        *x -= menu_allocation.width;
      else
        *x += allocation.width;
    }

  /* treat the default align value like START */
  if (align == GTK_ALIGN_FILL)
    align = GTK_ALIGN_START;

  if (align == GTK_ALIGN_CENTER)
    *y -= (menu_allocation.height - allocation.height) / 2;
  else if (align == GTK_ALIGN_END)
    *y -= menu_allocation.height - allocation.height;

  *push_in = FALSE;
}
Exemplo n.º 17
0
static void
menu_position_up_down_func (GtkMenu       *menu,
                            gint          *x,
                            gint          *y,
                            gboolean      *push_in,
                            GtkMenuButton *menu_button)
{
  GtkMenuButtonPrivate *priv = menu_button->priv;
  GtkWidget *widget = GTK_WIDGET (menu_button);
  GtkWidget *toplevel;
  GtkTextDirection direction;
  GdkRectangle monitor;
  gint monitor_num;
  GdkScreen *screen;
  GdkWindow *window;
  GtkAllocation menu_allocation, allocation, arrow_allocation;
  GtkAlign align;

  /* In the common case the menu button is showing a dropdown menu, set the
   * corresponding type hint on the toplevel, so the WM can omit the top side
   * of the shadows.
   */
  if (priv->arrow_type == GTK_ARROW_DOWN)
    {
      toplevel = gtk_widget_get_toplevel (priv->menu);
      gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
    }

  align = gtk_widget_get_halign (priv->menu);
  direction = gtk_widget_get_direction (widget);
  window = gtk_widget_get_window (priv->align_widget ? priv->align_widget : widget);

  screen = gtk_widget_get_screen (GTK_WIDGET (menu));
  monitor_num = gdk_screen_get_monitor_at_window (screen, window);
  if (monitor_num < 0)
    monitor_num = 0;
  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);

  gtk_widget_get_allocation (priv->align_widget ? priv->align_widget : widget, &allocation);
  gtk_widget_get_allocation (widget, &arrow_allocation);
  gtk_widget_get_allocation (priv->menu, &menu_allocation);

  gdk_window_get_origin (window, x, y);
  *x += allocation.x;
  *y += allocation.y;

  /* treat the default align value like START */
  if (align == GTK_ALIGN_FILL)
    align = GTK_ALIGN_START;

  if (align == GTK_ALIGN_CENTER)
    *x -= (menu_allocation.width - allocation.width) / 2;
  else if ((align == GTK_ALIGN_START && direction == GTK_TEXT_DIR_LTR) ||
           (align == GTK_ALIGN_END && direction == GTK_TEXT_DIR_RTL))
    *x += MAX (allocation.width - menu_allocation.width, 0);
  else if (menu_allocation.width > allocation.width)
    *x -= menu_allocation.width - allocation.width;

  if (priv->arrow_type == GTK_ARROW_UP && *y - menu_allocation.height >= monitor.y)
    {
      *y -= menu_allocation.height;
    }
  else
    {
      if ((*y + arrow_allocation.height + menu_allocation.height) <= monitor.y + monitor.height)
        *y += arrow_allocation.height;
      else if ((*y - menu_allocation.height) >= monitor.y)
        *y -= menu_allocation.height;
      else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y)
        *y += arrow_allocation.height;
      else
        *y -= menu_allocation.height;
    }

  *push_in = FALSE;
}
Exemplo n.º 18
0
static void
gtk_popup_button_popup_real (GtkPopupButton *popup_button, GdkDevice *device)
{
	GtkPopupButtonPrivate *priv = popup_button->priv;
	GtkAllocation button_allocation, dock_allocation;
	GdkScreen *screen;
	gint monitor_num;
	GdkRectangle monitor;
	GtkWidget *toplevel;
	GdkDevice *keyboard, *pointer;
	guint32 time;
	gint x, y;
	
	g_return_if_fail (GTK_IS_POPUP_BUTTON (popup_button));
	g_return_if_fail (GDK_IS_DEVICE (device));
	
	if (!gtk_widget_get_realized (GTK_WIDGET (popup_button)))
		return;
	
	if (gtk_widget_get_mapped (priv->dock))
		return;
	
	if (priv->grab_pointer && priv->grab_keyboard)
		return;
	
	time = gtk_get_current_event_time ();
	
	if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) {
		keyboard = device;
		pointer = gdk_device_get_associated_device (device);
	} else {
		pointer = device;
		keyboard = gdk_device_get_associated_device (device);
	}
	
	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (popup_button));
	if (GTK_IS_WINDOW (toplevel))
		gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
				GTK_WINDOW (priv->dock));
	
	/* positioning */
	gtk_widget_show (priv->dock);
	gtk_widget_get_allocation (GTK_WIDGET (popup_button), &button_allocation);
	gdk_window_get_root_coords (gtk_widget_get_window (GTK_WIDGET (popup_button)),
			button_allocation.x, button_allocation.y, &x, &y);
	gtk_widget_get_allocation (GTK_WIDGET (priv->dock), &dock_allocation);
	
	x = (x + button_allocation.width / 2) - (dock_allocation.width / 2);
	y = y - dock_allocation.height;
	
	GdkWindow *window = window = gtk_widget_get_window (GTK_WIDGET (popup_button));
	screen = gtk_widget_get_screen (GTK_WIDGET (priv->dock));
	monitor_num = gdk_screen_get_monitor_at_window (screen, window);
	gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
	
	if (x < monitor.x)
		x = monitor.x;
	else if (x + dock_allocation.width > monitor.x + monitor.width)
		x = monitor.x + monitor.width - dock_allocation.width;
	
	gtk_window_move (GTK_WINDOW (priv->dock), x, y);
	
	/* grabbing */
	gtk_widget_grab_focus (priv->dock);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (popup_button), TRUE);
	
	if (gdk_device_grab (pointer, gtk_widget_get_window (priv->dock),
			GDK_OWNERSHIP_WINDOW, TRUE,
			GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
			NULL, time) != GDK_GRAB_SUCCESS) {
		gtk_device_grab_remove (priv->dock, pointer);
		gtk_widget_hide (priv->dock);
		return;
	}
	
	if (gdk_device_grab (keyboard, gtk_widget_get_window (priv->dock),
			GDK_OWNERSHIP_WINDOW, TRUE,
			GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
			NULL, time) != GDK_GRAB_SUCCESS) {
		gdk_device_ungrab (pointer, time);
		gtk_device_grab_remove (priv->dock, pointer);
		gtk_widget_hide (priv->dock);
		return;
	}
	
	gtk_device_grab_add (priv->dock, pointer, TRUE);
	priv->grab_pointer = pointer;
	priv->grab_keyboard = keyboard;
}
Exemplo n.º 19
0
void rdp_connect(GtkButton *connect, gpointer erdp) {
    /*get the string info*/
    GtkEntry *rip = (GtkEntry *) find_child(erdp, "address");
    GtkEntry *ruser = (GtkEntry *) find_child(erdp, "user");
    GtkEntry *rpass = (GtkEntry *) find_child(erdp, "pass");
    GtkEntry *arguments = (GtkEntry *) find_child(erdp, "arguments");
    GtkCheckButton *fullscreen = (GtkCheckButton *) find_child(erdp, "fullscreen");
    GtkCheckButton *decorations = (GtkCheckButton *) find_child(erdp, "decorations");
    GtkCheckButton *smartscaling = (GtkCheckButton *) find_child(erdp, "smartscaling");
    GtkCheckButton *sound = (GtkCheckButton *) find_child(erdp, "sound");
    GtkCheckButton *clipboard = (GtkCheckButton *) find_child(erdp, "clipboard");
    GtkCheckButton *homedir = (GtkCheckButton *) find_child(erdp, "homedir");

    char *xfreerdp = find_executable("xfreerdp");
    printf("Xfreerdp path: %s\n", xfreerdp);

    /*format my strings correctly*/
    char *fip = g_strconcat("/v:", gtk_entry_get_text(rip), NULL);
    char *fuser = g_strconcat("/u:", gtk_entry_get_text(ruser), NULL);
    char *fpass = g_strconcat("/p:", gtk_entry_get_text(rpass), NULL);

    /*check to see if the connection is valid*/
    if(check_connect(fip, fuser, fpass) != TRUE) {
        return;
    }

    /*check what options to add to rdp from the options tickboxes*/
    char **opts = malloc(sizeof(char *));
    opts[0] = NULL;
    opts = add_opt(&opts, xfreerdp);
    opts = add_opt(&opts, "/cert-ignore");
    opts = add_opt(&opts, "/auto-reconnect");
    opts = add_opt(&opts, fip);
    opts = add_opt(&opts, fuser);
    opts = add_opt(&opts, fpass);

    if(gtk_toggle_button_get_active((GtkToggleButton*)fullscreen) == TRUE) {
        opts = add_opt(&opts, "/f");
    }
    if(gtk_toggle_button_get_active((GtkToggleButton*)decorations) == TRUE) {
        opts = add_opt(&opts, "/disp");
        opts = add_opt(&opts, "/fonts");
        opts = add_opt(&opts, "/aero");
        opts = add_opt(&opts, "/window-drag");
        opts = add_opt(&opts, "/menu-anims");
    }
    if(gtk_toggle_button_get_active((GtkToggleButton*)smartscaling) == TRUE) {
        GdkRectangle *workarea = g_new(GdkRectangle, 1);
        GdkScreen *screen = gdk_screen_get_default();
        gint monitor = gdk_screen_get_primary_monitor(screen);
        gdk_screen_get_monitor_workarea(screen, monitor, workarea);
        int width = workarea->width;
        int height = workarea->height;
        char sizebuff[32];
        snprintf(sizebuff, 31, "/size:%dx%d", width, height);
        opts = add_opt(&opts, sizebuff);
        snprintf(sizebuff, 31, "/smart-sizing:%dx%d", width, height);
        opts = add_opt(&opts, sizebuff);
    }
    if(gtk_toggle_button_get_active((GtkToggleButton*)sound) == TRUE) {
        opts = add_opt(&opts, "/sound");
    }
    if(gtk_toggle_button_get_active((GtkToggleButton*)clipboard) == TRUE) {
        opts = add_opt(&opts, "/clipboard");
    }
    if(gtk_toggle_button_get_active((GtkToggleButton*)homedir) == TRUE) {
        opts = add_opt(&opts, "/home-drive");
    }

    /* add the user specified options. We do no error checking */
    char *argtext = strdup(gtk_entry_get_text(arguments));
    char *argbuff = strtok(argtext, " ");
    while(argbuff != NULL) {
        opts = add_opt(&opts, argbuff);
        strtok(NULL, " ");
    }

    /*and call xfreerdp*/
    int i;
    printf("Calling: ");
    for(i=0; opts[i] != NULL; i++) {
        if(strncmp(opts[i], "/p:", 3) == 0) {
            printf("/p:**** ");
            continue;
        }
        printf("%s ", opts[i]);
    }
    printf("\n");
    execv(xfreerdp, opts);
    /*code never gets here*/
    return;
}
Exemplo n.º 20
0
/**
 * gimp_session_info_apply_geometry:
 * @info:
 * @screen:
 * @current_monitor:
 *
 * Apply the geometry stored in the session info object to the
 * associated widget.
 **/
void
gimp_session_info_apply_geometry (GimpSessionInfo *info,
                                  GdkScreen       *screen,
                                  gint             current_monitor,
                                  gboolean         apply_stored_monitor)
{
  GdkRectangle rect;
  GdkRectangle work_rect;
  gchar        geom[32];
  gint         monitor;
  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_SCREEN (screen));

  monitor = current_monitor;

  if (apply_stored_monitor)
    {
      gint n_monitors;

      n_monitors = gdk_screen_get_n_monitors (screen);

      if (info->p->monitor != DEFAULT_MONITOR &&
          info->p->monitor < n_monitors)
        {
          monitor = info->p->monitor;
        }
      else
        {
          monitor = gdk_screen_get_primary_monitor (screen);
        }
    }

  gdk_screen_get_monitor_geometry (screen, monitor, &rect);
  gdk_screen_get_monitor_workarea (screen, 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_size_request (info->p->widget, &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 (info->p->right_align && info->p->bottom_align)
    {
      g_strlcpy (geom, "-0-0", sizeof (geom));
    }
  else if (info->p->right_align)
    {
      g_snprintf (geom, sizeof (geom), "-0%+d", info->p->y);
    }
  else if (info->p->bottom_align)
    {
      g_snprintf (geom, sizeof (geom), "%+d-0", info->p->x);
    }
  else
    {
      g_snprintf (geom, sizeof (geom), "%+d%+d", info->p->x, info->p->y);
    }

  gtk_window_parse_geometry (GTK_WINDOW (info->p->widget), geom);

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

  /*  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_DIALOG (info->p->widget))
    g_signal_connect (info->p->widget, "show",
                      G_CALLBACK (gimp_session_info_dialog_show),
                      info);
}
Exemplo n.º 21
0
int
main (int argc, char **argv)
{
  GtkWidget *window;
  GdkScreen *screen;
  int monitor;
  GdkRectangle rect;
  GError *error = NULL;
  char *font = NULL;
  char **remaining = NULL;
  GtkApplication *application;
  guint status;
  GOptionEntry goptions[] =
  {
    { "font", 0, 0, G_OPTION_ARG_STRING, &font,
      N_("Font to start with; ex: 'Serif 27'"), N_("FONT") },
    { "version", 0, G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG, 
      G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
    { "print", 'p', 0, G_OPTION_ARG_CALLBACK, option_print_cb,
      "Print characters in string", "STRING" },
    { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
      NULL, N_("[STRING…]") },
    { NULL }
  };

  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  /* Not interested in silly debug spew polluting the journal, bug #749195 */
  if (g_getenv ("G_ENABLE_DIAGNOSTIC") == NULL)
    g_setenv ("G_ENABLE_DIAGNOSTIC", "0", TRUE);

  /* Set programme name explicitly (see bug #653115) */
  g_set_prgname("gucharmap");

  if (!gtk_init_with_args (&argc, &argv, NULL, goptions, GETTEXT_PACKAGE, &error))
    {
      g_printerr ("%s\n", error->message);
      g_error_free (error);

      exit (1);
    }

  g_set_application_name (_("Character Map"));
  gtk_window_set_default_icon_name (GUCHARMAP_ICON_NAME);

  application = gtk_application_new ("org.gnome.Charmap",
                                     G_APPLICATION_NON_UNIQUE);
  g_signal_connect (application, "startup", G_CALLBACK (startup_cb), NULL);
  g_signal_connect (application, "activate",
                    G_CALLBACK (gucharmap_activate), NULL);

  g_application_register (G_APPLICATION (application), NULL, NULL);

  /* Gucharmap doesn't work right with the dark theme, see #741939. 
   * Apparently this got fixed in gtk+ some time before 3.22, so
   * only work around this on older versions.
   */
  if (gtk_check_version (3, 22, 0) != NULL /* < 3.22.0 */)
    g_object_set (gtk_settings_get_default (), "gtk-application-prefer-dark-theme", FALSE, NULL);

  window = gucharmap_window_new (application);

  screen = gtk_window_get_screen (GTK_WINDOW (window));
  monitor = gdk_screen_get_monitor_at_point (screen, 0, 0);
#if GTK_CHECK_VERSION (3, 3, 5)
  gdk_screen_get_monitor_workarea (screen, monitor, &rect);
#else
  gdk_screen_get_monitor_geometry (screen, monitor, &rect);
#endif
  gtk_window_set_default_size (GTK_WINDOW (window), rect.width * 9/16, rect.height * 9/16);

  if (font)
    {
      gucharmap_window_set_font (GUCHARMAP_WINDOW (window), font);
      g_free (font);
    }

  gtk_window_present (GTK_WINDOW (window));

  if (remaining) {
    char *str = g_strjoinv (" ", remaining);
    gucharmap_window_search (GUCHARMAP_WINDOW (window), str);
    g_free (str);
    g_strfreev (remaining);
  }

  status = g_application_run (G_APPLICATION (application), argc, argv);
  g_object_unref (application);

  return status;
}