Exemple #1
0
int main(int argc, char *argv[])
{
	GdkScreen *screen;
	gint width, height;
	gint index;
	gint point_1, point_2;
	gint mm_height, mm_width;
	GdkRectangle rect0, rect1;
	GdkWindow * wind;

	gtk_init(&argc, &argv);
	g_type_init();
	screen = gdk_screen_get_default();
	gint number = gdk_screen_get_n_monitors(screen);
	
	width = gdk_screen_get_width(screen);
	height = gdk_screen_get_height(screen);

	if(number > 1 )
	{
		index = gdk_screen_get_primary_monitor(screen);
		
		point_1 = gdk_screen_get_monitor_at_point(screen , 20, 20);
		point_2 = gdk_screen_get_monitor_at_point(screen , 2700, 20);

		printf("number is %d\n width %d\t height %d\n primary monitor index %d\n", number, width, height, index);

		printf("point1 is in monitor %d\n", point_1);
		printf("point2 is in monitor %d\n", point_2);
/*
		mm_height = gdk_screen_get_monitor_height_mm (screen, 0);
		printf("monitor0 height  %d\n", mm_height);
		mm_height = gdk_screen_get_monitor_height_mm (screen, 1);
		printf("monitor1 height  %d\n", mm_height);
		
		mm_width = gdk_screen_get_monitor_width_mm (screen, 0);
		printf("monitor0 width  %d\n", mm_width);
		mm_width = gdk_screen_get_monitor_width_mm (screen, 1);
		printf("monitor1 width  %d\n", mm_width);
*/
		gdk_screen_get_monitor_geometry(screen, 0, &rect0);
		printf("monitor0 rect.x %d rect.y %d\n rect.width %d rect.weight %d\n", rect0.x, rect0.y, rect0.width, rect0.height);
		
		gdk_screen_get_monitor_geometry(screen, 1, &rect1);
		printf("monitor1 rect.x %d rect.y %d\n rect.width %d rect.weight %d\n", rect1.x, rect1.y, rect1.width, rect1.height);

		wind = gdk_screen_get_active_window(screen);
		gint monitor = gdk_screen_get_monitor_at_window(screen, wind);
		printf("active window at monitor   %d\n", monitor);

	}
    else{
		printf("sorry, only one monitor! \n");
    }
}
Exemple #2
0
static gboolean
manager_maybe_grab_window (GSManager *manager,
                           GSWindow  *window)
{
	GdkDisplay *display;
	GdkScreen  *screen;
	int         monitor;
	int         x, y;
	gboolean    grabbed;

	display = gdk_display_get_default ();
	gdk_display_get_pointer (display, &screen, &x, &y, NULL);
	monitor = gdk_screen_get_monitor_at_point (screen, x, y);

	gdk_flush ();
	grabbed = FALSE;
	if (gs_window_get_screen (window) == screen
	        && gs_window_get_monitor (window) == monitor)
	{
		gs_debug ("Moving grab to %p", window);
		gs_grab_move_to_window (manager->priv->grab,
		                        gs_window_get_gdk_window (window),
		                        gs_window_get_screen (window),
		                        FALSE);
		grabbed = TRUE;
	}

	return grabbed;
}
Exemple #3
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));
}
Exemple #4
0
static GdkPixbuf* get_screenshot ()
{
  GdkWindow *root_window = gdk_get_default_root_window ();
  gint x, y;
  gint swidth, sheight;

  guint m_offset_x = 0, m_offset_y = 0;
  gint monitors = gdk_screen_get_n_monitors (gdk_screen_get_default ());
  if (monitors > 1) {
    gint px = 0, py = 0;
    gdk_display_get_pointer (gdk_display_get_default (), NULL, &px, &py, NULL);
    gint current_monitor = gdk_screen_get_monitor_at_point (gdk_screen_get_default (), px, py);
    for (int i = 0; i < current_monitor; i++) {
      GdkRectangle mon_rect;
      gdk_screen_get_monitor_geometry (gdk_screen_get_default (), i, &mon_rect);
      m_offset_x += mon_rect.width;
      m_offset_y += mon_rect.height;
    }
  }

  gdk_drawable_get_size (root_window, &swidth, &sheight);
  gdk_window_get_origin (root_window, &x, &y);

  if (swidth <= m_offset_x)
    m_offset_x = 0;
  if (sheight <= m_offset_y)
    m_offset_y = 0;

  return gdk_pixbuf_get_from_drawable (NULL, root_window, NULL,
				       x + options.screenshot_offset_x + m_offset_x,
				       y + options.screenshot_offset_y + m_offset_y,
				       0, 0,
				       swidth - options.screenshot_offset_x - m_offset_x,
				       sheight - options.screenshot_offset_y - m_offset_y);
}
Exemple #5
0
void cgraphics_menu_popup( widget_t *menu, int x, int y, int flags )
{
	GdkScreen *screen;
	GtkRequisition requisition;
	GdkRectangle monitor;
	GtkWidget *widget = GTK_WIDGET(menu->native);
	
	if ( flags & cMenuPopupAtCursor )
	{
		gtk_menu_popup( menu->native, NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time( ) );
		return;
	}
	
	gtk_widget_size_request( widget, &requisition );
	
	screen = gtk_widget_get_screen( widget );
	gdk_screen_get_monitor_geometry( screen, gdk_screen_get_monitor_at_point( screen, x, y ), &monitor );
	
	/* FIXME: This might not be correct */
	if ( y + requisition.height > monitor.height )
		y -= requisition.height;
	
	menu->size.x = x;
	menu->size.y = y;
	
	gtk_menu_popup( menu->native, NULL, NULL, cgraphics_menu_position, menu, 0, gtk_get_current_event_time( ) );
}
Exemple #6
0
static void moveBeamerToMouseMonitor(void)
{
	GdkDisplay *dpy = NULL;
	GdkScreen *scr = NULL;
	GdkRectangle rect;
	int mx = -1, my = -1, mon = -1;

	/* Open default display. Then get the current position of the mouse
	 * cursor and the screen that cursor is on. */
	dpy = gdk_display_get_default();
	if (dpy == NULL)
	{
		/* Actually, this should not happen because we are already able
		 * to create windows on the default screen. */
		fprintf(stderr, "Could not get default display.\n");
		return;
	}
	gdk_display_get_pointer(dpy, &scr, &mx, &my, NULL);

	/* Get the number of the monitor at the current mouse position, as
	 * well as the geometry (offset, size) of that monitor. */
	mon = gdk_screen_get_monitor_at_point(scr, mx, my);
	gdk_screen_get_monitor_geometry(scr, mon, &rect);

	/* Move the beamer window to the upper left corner of the current
	 * monitor. */
	gtk_window_move(GTK_WINDOW(win_beamer), rect.x, rect.y);
}
Exemple #7
0
/* If the menu is popped up in response to a keystroke, center it
 * immediately below the toolbar.
 */
static void
tm_popup_position_func(GtkMenu * menu, gint * x, gint * y,
                       gboolean * push_in, gpointer user_data)
{
    GtkWidget *toolbar = GTK_WIDGET(user_data);
    GdkScreen *screen = gtk_widget_get_screen(toolbar);
    GtkRequisition req;
    gint monitor_num;
    GdkRectangle monitor;
    GtkAllocation allocation;

    g_return_if_fail(gtk_widget_get_window(toolbar));

    gdk_window_get_origin(gtk_widget_get_window(toolbar), x, y);

    gtk_widget_get_preferred_size(GTK_WIDGET(menu), NULL, &req);

    gtk_widget_get_allocation(toolbar, &allocation);
    *x += (allocation.width - req.width) / 2;
    *y += allocation.height;

    monitor_num = gdk_screen_get_monitor_at_point(screen, *x, *y);
    gtk_menu_set_monitor(menu, monitor_num);
    gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor);

    *x = CLAMP(*x, monitor.x,
               monitor.x + MAX(0, monitor.width - req.width));
    *y = CLAMP(*y, monitor.y,
               monitor.y + MAX(0, monitor.height - req.height));

    *push_in = FALSE;
}
Exemple #8
0
static gchar *
gui_get_display_name (Gimp *gimp,
                      gint  display_ID,
                      gint *monitor_number)
{
  GimpDisplay *display = NULL;
  GdkScreen   *screen;
  gint         monitor;

  if (display_ID > 0)
    display = gimp_display_get_by_ID (gimp, display_ID);

  if (display)
    {
      screen  = gtk_widget_get_screen (display->shell);
      monitor = gdk_screen_get_monitor_at_window (screen,
                                                  display->shell->window);
    }
  else
    {
      gint x, y;

      gdk_display_get_pointer (gdk_display_get_default (),
                               &screen, &x, &y, NULL);
      monitor = gdk_screen_get_monitor_at_point (screen, x, y);
    }

  *monitor_number = monitor;

  if (screen)
    return gdk_screen_make_display_name (screen);

  return NULL;
}
void
meta_fixed_tip_show (Display *xdisplay, int screen_number,
                     int root_x, int root_y,
                     const char *markup_text)
{
  int w, h;
  
  if (tip == NULL)
    {      
      tip = gtk_window_new (GTK_WINDOW_POPUP);
      gtk_window_set_type_hint (GTK_WINDOW(tip), GDK_WINDOW_TYPE_HINT_TOOLTIP);

      {
        GdkScreen *gdk_screen;
	GdkRectangle monitor;
	gint mon_num;

        gdk_screen = gdk_display_get_screen (gdk_display_get_default (),
                                             screen_number);
        gtk_window_set_screen (GTK_WINDOW (tip),
                               gdk_screen);
	mon_num = gdk_screen_get_monitor_at_point (gdk_screen, root_x, root_y);
	gdk_screen_get_monitor_geometry (gdk_screen, mon_num, &monitor);
	screen_right_edge = monitor.x + monitor.width;
	screen_bottom_edge = monitor.y + monitor.height;
      }
      
      gtk_widget_set_app_paintable (tip, TRUE);
      gtk_window_set_resizable (GTK_WINDOW (tip), FALSE);
      gtk_widget_set_name (tip, "gtk-tooltips");
      gtk_container_set_border_width (GTK_CONTAINER (tip), 4);

      g_signal_connect_swapped (tip, "expose_event",
				 G_CALLBACK (expose_handler), NULL);

      label = gtk_label_new (NULL);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
      gtk_widget_show (label);
      
      gtk_container_add (GTK_CONTAINER (tip), label);

      g_signal_connect (tip, "destroy",
			G_CALLBACK (gtk_widget_destroyed), &tip);
    }

  gtk_label_set_markup (GTK_LABEL (label), markup_text);
  
  gtk_window_get_size (GTK_WINDOW (tip), &w, &h);

  if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
      root_x = MAX(0, root_x - w);

  if ((root_x + w) > screen_right_edge)
    root_x -= (root_x + w) - screen_right_edge;
  
  gtk_window_move (GTK_WINDOW (tip), root_x, root_y);

  gtk_widget_show (tip);
}
Exemple #10
0
static void
position_window (GtkWindow *dialog)
{
    GdkPoint *coord;
    int screen_width, screen_height, monitor_num;
    GdkRectangle monitor;
    GdkScreen *screen;
    GtkRequisition req;

    g_signal_handlers_disconnect_by_func (dialog,
                                          (gpointer) position_window,
                                          NULL);

    coord = (GdkPoint*) g_object_get_data (G_OBJECT (dialog), "moo-coords");
    g_return_if_fail (coord != NULL);

    screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
    g_return_if_fail (screen != NULL);

    screen_width = gdk_screen_get_width (screen);
    screen_height = gdk_screen_get_height (screen);
    monitor_num = gdk_screen_get_monitor_at_point (screen, coord->x, coord->y);

    gtk_widget_size_request (GTK_WIDGET (dialog), &req);

    coord->x = coord->x - req.width / 2;
    coord->y = coord->y - req.height / 2;
    coord->x = CLAMP (coord->x, 0, screen_width - req.width);
    coord->y = CLAMP (coord->y, 0, screen_height - req.height);

    gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
    clamp_window_to_rectangle (&coord->x, &coord->y, req.width, req.height, &monitor);

    gtk_window_move (dialog, coord->x, coord->y);
}
Exemple #11
0
static gboolean
manager_maybe_grab_window (GSManager *manager,
                           GSWindow  *window)
{
        GdkDisplay *display;
        GdkScreen  *screen;
        int         monitor;
        int         x, y;
        gboolean    grabbed;

        display = gdk_display_get_default ();
#if GTK_CHECK_VERSION(3, 0, 0)
        GdkDeviceManager *device_manager = gdk_display_get_device_manager (display);
        GdkDevice *pointer = gdk_device_manager_get_client_pointer (device_manager);
        gdk_device_get_position (pointer, &screen, &x, &y);
#else
        gdk_display_get_pointer (display, &screen, &x, &y, NULL);
#endif
        monitor = gdk_screen_get_monitor_at_point (screen, x, y);

        gdk_flush ();
        grabbed = FALSE;
        if (gs_window_get_screen (window) == screen
            && gs_window_get_monitor (window) == monitor) {
                gs_debug ("Moving grab to %p", window);
                gs_grab_move_to_window (manager->priv->grab,
                                        gs_window_get_gdk_window (window),
                                        gs_window_get_screen (window),
                                        TRUE);
                grabbed = TRUE;
        }

        return grabbed;
}
Exemple #12
0
gint
gimp_widget_get_monitor (GtkWidget *widget)
{
    GdkWindow     *window;
    GdkScreen     *screen;
    GtkAllocation  allocation;
    gint           x, y;

    g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);

    window = gtk_widget_get_window (widget);

    if (! window)
        return gimp_get_monitor_at_pointer (&screen);

    screen = gtk_widget_get_screen (widget);

    gdk_window_get_origin (window, &x, &y);
    gtk_widget_get_allocation (widget, &allocation);

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

    x += allocation.width  / 2;
    y += allocation.height / 2;

    return gdk_screen_get_monitor_at_point (screen, x, y);
}
Exemple #13
0
void remmina_file_update_screen_resolution(RemminaFile *remminafile)
{
	GdkScreen *screen;
	gchar *pos;
	gchar *resolution;
	gint x, y;
	gint monitor;
	GdkRectangle rect;

	resolution = g_strdup(remmina_file_get_string(remminafile, "resolution"));
	if (resolution == NULL || strchr(resolution, 'x') == NULL)
	{
		gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, NULL);
		monitor = gdk_screen_get_monitor_at_point(screen, x, y);
		gdk_screen_get_monitor_geometry(screen, monitor, &rect);
		remmina_file_set_int(remminafile, "resolution_width", rect.width);
		remmina_file_set_int(remminafile, "resolution_height", rect.height);
	}
	else
	{
		pos = strchr(resolution, 'x');
		*pos++ = '\0';
		remmina_file_set_int(remminafile, "resolution_width", MAX(100, MIN(4096, atoi(resolution))));
		remmina_file_set_int(remminafile, "resolution_height", MAX(100, MIN(4096, atoi(pos))));
	}
	g_free(resolution);
}
Exemple #14
0
/* Determine where to pop up menu (if not activated by a mouse event) */
static void place_menu(GtkMenu *menu, gint *x, gint *y,
                       gboolean *push_in, gpointer data)
{
	TilemDisasmView *dv = data;
	GtkTreePath *path;
	GdkRectangle rect;
	GdkWindow *win;
	GdkScreen *screen;
	int n;

	win = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(dv));
	gdk_window_get_origin(win, x, y);

	gtk_tree_view_get_cursor(GTK_TREE_VIEW(dv), &path, NULL);
	if (path) {
		gtk_tree_view_get_cell_area(GTK_TREE_VIEW(dv), path, NULL, &rect);
		gtk_tree_path_free(path);
		*y += rect.y + rect.height;
	}

	screen = gdk_drawable_get_screen(win);
	n = gdk_screen_get_monitor_at_point(screen, *x, *y);
	gtk_menu_set_monitor(menu, n);

	*push_in = FALSE;
}
static void
setup_tooltip_window_position(gpointer data, int w, int h)
{
	int sig;
	int scr_w, scr_h, x, y, dy;
	int mon_num;
	GdkScreen *screen = NULL;
	GdkRectangle mon_size;
	GtkWidget *tipwindow = pidgin_tooltip.tipwindow;
	
	gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, NULL);
	mon_num = gdk_screen_get_monitor_at_point(screen, x, y);
	gdk_screen_get_monitor_geometry(screen, mon_num, &mon_size);

	scr_w = mon_size.width + mon_size.x;
	scr_h = mon_size.height + mon_size.y;

	dy = gdk_display_get_default_cursor_size(gdk_display_get_default()) / 2;

	if (w > mon_size.width)
		w = mon_size.width - 10;

	if (h > mon_size.height)
		h = mon_size.height - 10;

	x -= ((w >> 1) + 4);

	if ((y + h + 4) > scr_h)
		y = y - h - dy - 5;
	else
		y = y + dy + 6;

	if (y < mon_size.y)
		y = mon_size.y;

	if (y != mon_size.y) {
		if ((x + w) > scr_w)
			x -= (x + w + 5) - scr_w;
		else if (x < mon_size.x)
			x = mon_size.x;
	} else {
		x -= (w / 2 + 10);
		if (x < mon_size.x)
			x = mon_size.x;
	}

	gtk_widget_set_size_request(tipwindow, w, h);
	gtk_window_move(GTK_WINDOW(tipwindow), x, y);
	gtk_widget_show(tipwindow);

	g_signal_connect(G_OBJECT(tipwindow), "expose_event",
			G_CALLBACK(pidgin_tooltip_expose_event), data);

	/* Hide the tooltip when the widget is destroyed */
	sig = g_signal_connect(G_OBJECT(pidgin_tooltip.widget), "destroy", G_CALLBACK(pidgin_tooltip_destroy), NULL);
	g_signal_connect_swapped(G_OBJECT(tipwindow), "destroy", G_CALLBACK(g_source_remove), GINT_TO_POINTER(sig));
}
/**
 * gpm_backlight_dialog_show:
 *
 * Show the brightness popup, and place it nicely on the screen.
 **/
static void
gpm_backlight_dialog_show (GpmBacklight *backlight)
{
	int            orig_w;
	int            orig_h;
	int            screen_w;
	int            screen_h;
	int            x;
	int            y;
	int            pointer_x;
	int            pointer_y;
	GtkRequisition win_req;
	GdkScreen     *pointer_screen;
	GdkRectangle   geometry;
	int            monitor;

	/*
	 * get the window size
	 * if the window hasn't been mapped, it doesn't necessarily
	 * know its true size, yet, so we need to jump through hoops
	 */
	gtk_window_get_default_size (GTK_WINDOW (backlight->priv->popup), &orig_w, &orig_h);
	gtk_widget_size_request (backlight->priv->popup, &win_req);

	if (win_req.width > orig_w) {
		orig_w = win_req.width;
	}
	if (win_req.height > orig_h) {
		orig_h = win_req.height;
	}

	pointer_screen = NULL;
	gdk_display_get_pointer (gtk_widget_get_display (backlight->priv->popup),
				 &pointer_screen,
				 &pointer_x,
				 &pointer_y,
				 NULL);
	monitor = gdk_screen_get_monitor_at_point (pointer_screen,
						   pointer_x,
						   pointer_y);

	gdk_screen_get_monitor_geometry (pointer_screen,
					 monitor,
					 &geometry);

	screen_w = geometry.width;
	screen_h = geometry.height;

	x = ((screen_w - orig_w) / 2) + geometry.x;
	y = geometry.y + (screen_h / 2) + (screen_h / 2 - orig_h) / 2;

	gtk_window_move (GTK_WINDOW (backlight->priv->popup), x, y);

	gtk_widget_show (backlight->priv->popup);

	gdk_display_sync (gtk_widget_get_display (backlight->priv->popup));
}
Exemple #17
0
static void
nimf_candidate_show (NimfCandidatable *candidatable,
                     NimfServiceIC    *target,
                     gboolean          show_entry)
{
  g_debug (G_STRLOC ": %s", G_STRFUNC);

  NimfCandidate *candidate = NIMF_CANDIDATE (candidatable);

  GtkRequisition       natural_size;
  int                  x, y, w, h;
  GdkRectangle         geometry;
  const NimfRectangle *cursor_area;

  cursor_area = nimf_service_ic_get_cursor_location (target);

#if GTK_CHECK_VERSION (3, 22, 0)
  GdkDisplay *display = gtk_widget_get_display (candidate->window);
  GdkMonitor *monitor;
  monitor = gdk_display_get_monitor_at_point (display,
                                              cursor_area->x, cursor_area->y);
  gdk_monitor_get_geometry (monitor, &geometry);
#else
  GdkScreen *screen = gtk_widget_get_screen (candidate->window);
  gint  monitor_num = gdk_screen_get_monitor_at_point (screen,
                                                       cursor_area->x,
                                                       cursor_area->y);
  gdk_screen_get_monitor_geometry (screen, monitor_num, &geometry);
#endif

  candidate->target = target;

  if (show_entry)
    gtk_widget_show (candidate->entry);
  else
    gtk_widget_hide (candidate->entry);

  gtk_widget_show_all (candidate->window);
  gtk_widget_get_preferred_size (candidate->window, NULL, &natural_size);
  gtk_window_resize (GTK_WINDOW (candidate->window),
                     natural_size.width, natural_size.height);
  gtk_window_get_size (GTK_WINDOW (candidate->window), &w, &h);

  x = cursor_area->x - cursor_area->width;
  y = cursor_area->y + cursor_area->height;

  if (x + w > geometry.x + geometry.width)
    x = geometry.x + geometry.width - w;

  if ((y + h > geometry.y + geometry.height) &&
      ((cursor_area->y - h) >= geometry.y))
    y = cursor_area->y - h;

  gtk_window_move (GTK_WINDOW (candidate->window), x, y);
}
Exemple #18
0
static GdkRectangle current_monitor_size ()
{
  // Where is the pointer now?
  gint x, y;
  gdk_display_get_pointer (gdk_display_get_default (), NULL, &x, &y, NULL);
  gint monitor = gdk_screen_get_monitor_at_point (gdk_screen_get_default (), x, y);
  GdkRectangle rect;
  gdk_screen_get_monitor_geometry (gdk_screen_get_default (), monitor, &rect);

  return rect;
}
Exemple #19
0
gint
gimp_get_monitor_at_pointer (GdkScreen **screen)
{
    gint x, y;

    g_return_val_if_fail (screen != NULL, 0);

    gdk_display_get_pointer (gdk_display_get_default (),
                             screen, &x, &y, NULL);

    return gdk_screen_get_monitor_at_point (*screen, x, y);
}
static gboolean
gimp_view_popup_timeout (GimpViewPopup *popup)
{
  GtkWidget    *window;
  GtkWidget    *frame;
  GtkWidget    *view;
  GdkScreen    *screen;
  GdkRectangle  rect;
  gint          monitor;
  gint          x;
  gint          y;

  popup->timeout_id = 0;

  screen = gtk_widget_get_screen (popup->widget);

  window = gtk_window_new (GTK_WINDOW_POPUP);
  gtk_window_set_resizable (GTK_WINDOW (window), FALSE);

  gtk_window_set_screen (GTK_WINDOW (window), screen);

  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
  gtk_container_add (GTK_CONTAINER (window), frame);
  gtk_widget_show (frame);

  view = gimp_view_new_full (popup->context,
                             popup->viewable,
                             popup->popup_width,
                             popup->popup_height,
                             0, TRUE, FALSE, FALSE);
  gimp_view_renderer_set_dot_for_dot (GIMP_VIEW (view)->renderer,
                                      popup->dot_for_dot);
  gtk_container_add (GTK_CONTAINER (frame), view);
  gtk_widget_show (view);

  x = popup->button_x - (popup->popup_width  / 2);
  y = popup->button_y - (popup->popup_height / 2);

  monitor = gdk_screen_get_monitor_at_point (screen, x, y);
  gdk_screen_get_monitor_geometry (screen, monitor, &rect);

  x = CLAMP (x, rect.x, rect.x + rect.width  - popup->popup_width);
  y = CLAMP (y, rect.y, rect.y + rect.height - popup->popup_height);

  gtk_window_move (GTK_WINDOW (window), x, y);
  gtk_widget_show (window);

  popup->popup = window;

  return FALSE;
}
Exemple #21
0
void
adjust_position(int* x, int* y, int width, int height)
{
    GdkScreen *screen; 
    gint mon;
    GdkRectangle srect;
    screen = gdk_screen_get_default();
    mon = gdk_screen_get_monitor_at_point(screen, *x, *y);
    gdk_screen_get_monitor_geometry(screen, mon, &srect);
    LOG("srect: %dx%d+%d+%d", srect.width, srect.height, srect.x, srect.y);
    *x = in_range(*x, srect.x, srect.x + srect.width - width);
    *y = in_range(*y, srect.y, srect.y + srect.height - height);
}
Exemple #22
0
static void
gimp_ui_manager_menu_position (GtkMenu  *menu,
                               gint     *x,
                               gint     *y,
                               gpointer  data)
{
  GdkScreen      *screen;
  GtkRequisition  requisition;
  GdkRectangle    rect;
  gint            monitor;
  gint            pointer_x;
  gint            pointer_y;

  g_return_if_fail (GTK_IS_MENU (menu));
  g_return_if_fail (x != NULL);
  g_return_if_fail (y != NULL);
  g_return_if_fail (GTK_IS_WIDGET (data));

  gdk_display_get_pointer (gtk_widget_get_display (GTK_WIDGET (data)),
                           &screen, &pointer_x, &pointer_y, NULL);

  monitor = gdk_screen_get_monitor_at_point (screen, pointer_x, pointer_y);
  gdk_screen_get_monitor_geometry (screen, monitor, &rect);

  gtk_menu_set_screen (menu, screen);

  gtk_widget_size_request (GTK_WIDGET (menu), &requisition);

  if (gtk_widget_get_direction (GTK_WIDGET (menu)) == GTK_TEXT_DIR_RTL)
    {
      *x = pointer_x - 2 - requisition.width;

      if (*x < rect.x)
        *x = pointer_x + 2;
    }
  else
    {
      *x = pointer_x + 2;

      if (*x + requisition.width > rect.x + rect.width)
        *x = pointer_x - 2 - requisition.width;
    }

  *y = pointer_y + 2;

  if (*y + requisition.height > rect.y + rect.height)
    *y = pointer_y - 2 - requisition.height;

  if (*x < rect.x) *x = rect.x;
  if (*y < rect.y) *y = rect.y;
}
Exemple #23
0
void
hippo_ui_get_screen_info(HippoUI          *ui,
                         HippoRectangle   *monitor_rect_p,
                         HippoRectangle   *tray_icon_rect_p,
                         HippoOrientation *tray_icon_orientation_p)
{
    GtkOrientation orientation;
    GdkScreen *screen;
    GdkRectangle icon_rect;
    GdkRectangle monitor;
    int monitor_num;
    
    gtk_status_icon_get_geometry(GTK_STATUS_ICON(ui->icon),
                                 &screen, 
                                 &icon_rect, 
                                 &orientation);

    if (monitor_rect_p) {
        HippoRectangle work_area;

        monitor_num = gdk_screen_get_monitor_at_point(screen,
                                                      icon_rect.x + icon_rect.width / 2,
                                                      icon_rect.y + icon_rect.height / 2);
        if (monitor_num < 0)
            monitor_num = 0;
        
        gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor);
        
        monitor_rect_p->x = monitor.x;
        monitor_rect_p->y = monitor.y;
        monitor_rect_p->width = monitor.width;
        monitor_rect_p->height = monitor.height;
        
        screen_get_work_area(screen, &work_area);
        hippo_rectangle_intersect(monitor_rect_p, &work_area, monitor_rect_p);
    }

    if (tray_icon_rect_p) {
        tray_icon_rect_p->x = icon_rect.x;
        tray_icon_rect_p->y = icon_rect.y;
        tray_icon_rect_p->width = icon_rect.width;
        tray_icon_rect_p->height = icon_rect.height;
    }

    if (tray_icon_orientation_p) {
        if (orientation == GTK_ORIENTATION_VERTICAL)
            *tray_icon_orientation_p = HIPPO_ORIENTATION_VERTICAL;
        else
            *tray_icon_orientation_p = HIPPO_ORIENTATION_HORIZONTAL;
    }
}
int iupdrvCheckMainScreen(int *w, int *h)
{
  GdkScreen *screen = gdk_screen_get_default();
  int monitors_count = gdk_screen_get_n_monitors(screen);
  if (monitors_count > 1)
  {
    GdkRectangle rect;
    gdk_screen_get_monitor_geometry(screen, gdk_screen_get_monitor_at_point(screen, 0, 0), &rect);
    *w = rect.width;
    *h = rect.height;
    return 1;
  }
  return 0;
}
/**
 * gimp_menu_position:
 * @menu: a #GtkMenu widget
 * @x: pointer to horizontal position
 * @y: pointer to vertical position
 *
 * Positions a #GtkMenu so that it pops up on screen.  This function
 * takes care of the preferred popup direction (taken from the widget
 * render direction) and it handles multiple monitors representing a
 * single #GdkScreen (Xinerama).
 *
 * You should call this function with @x and @y initialized to the
 * origin of the menu. This is typically the center of the widget the
 * menu is popped up from. gimp_menu_position() will then decide if
 * and how these initial values need to be changed.
 **/
void
gimp_menu_position (GtkMenu *menu,
                    gint    *x,
                    gint    *y)
{
  GtkWidget      *widget;
  GdkScreen      *screen;
  GtkRequisition  requisition;
  GdkRectangle    rect;
  gint            monitor;

  g_return_if_fail (GTK_IS_MENU (menu));
  g_return_if_fail (x != NULL);
  g_return_if_fail (y != NULL);

  widget = GTK_WIDGET (menu);

  screen = gtk_widget_get_screen (widget);

  monitor = gdk_screen_get_monitor_at_point (screen, *x, *y);
  gdk_screen_get_monitor_geometry (screen, monitor, &rect);

  gtk_menu_set_screen (menu, screen);

  gtk_widget_size_request (widget, &requisition);

  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
    {
      *x -= requisition.width;
      if (*x < rect.x)
        *x += requisition.width;
    }
  else
    {
      if (*x + requisition.width > rect.x + rect.width)
        *x -= requisition.width;
    }

  if (*x < rect.x)
    *x = rect.x;

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

  if (*y < rect.y)
    *y = rect.y;
}
Exemple #26
0
static void do_show_volume_scale(GdkRectangle *rect_or_null)
{
    // Create the scale if needed
    if (!window)
        create_volume_scale();

    // Cancel any flashing timeout
    if (flashing)
        g_source_remove(flashing_timeout_id);

    // Update the volume level
    changing_scale_value = TRUE;
    gtk_range_set_value(GTK_RANGE(scale), shared_audio_status()->volume);
    changing_scale_value = FALSE;

    if (rect_or_null) {
        // Determine where the window will be
        gint size_x, size_y;
        gtk_window_get_size(GTK_WINDOW(window), &size_x, &size_y);
        gint x = rect_or_null->x + (rect_or_null->width - size_x) / 2;
        gint y = rect_or_null->y - size_y;

        // Find the coordinates of the monitor
        GdkRectangle monitor_rect;
        GdkScreen *screen = gtk_widget_get_screen(window);
        gint monitor = gdk_screen_get_monitor_at_point(screen, rect_or_null->x, rect_or_null->y);
        gdk_screen_get_monitor_geometry(screen, monitor, &monitor_rect);

        // If the Y position is outside the monitor rect, the tray is at the top
        if (y < monitor_rect.y) {
            y = rect_or_null->y + rect_or_null->height;
        }

        // Position the window
        gtk_window_move(GTK_WINDOW(window), x, y);
    }

    // Show the window
    gtk_window_present(GTK_WINDOW(window));

    // We're visible now, but not flashing
    visible = TRUE;
    flashing = FALSE;
}
Exemple #27
0
static void
position_window (MateRRLabeler  *labeler,
		 GtkWidget       *window,
		 int              x,
		 int              y)
{
	GdkRectangle    workarea;
	GdkRectangle    monitor;
	int             monitor_num;

	get_work_area (labeler, &workarea);
	monitor_num = gdk_screen_get_monitor_at_point (labeler->priv->screen, x, y);
	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);
}
Exemple #28
0
/* This function mostly lifted from
 * gtk+/gdk/gdkscreen.c:gdk_screen_get_monitor_at_window()
 */
static gint
gimp_session_info_get_appropriate_monitor (GdkScreen *screen,
                                           gint       x,
                                           gint       y,
                                           gint       w,
                                           gint       h)
{
  GdkRectangle rect;
  gint         area    = 0;
  gint         monitor = -1;
  gint         num_monitors;
  gint         i;

  rect.x      = x;
  rect.y      = y;
  rect.width  = w;
  rect.height = h;

  num_monitors = gdk_screen_get_n_monitors (screen);

  for (i = 0; i < num_monitors; i++)
    {
      GdkRectangle geometry;

      gdk_screen_get_monitor_geometry (screen, i, &geometry);

      if (gdk_rectangle_intersect (&rect, &geometry, &geometry) &&
          geometry.width * geometry.height > area)
        {
          area = geometry.width * geometry.height;
          monitor = i;
        }
    }

  if (monitor >= 0)
    return monitor;
  else
    return gdk_screen_get_monitor_at_point (screen,
                                            rect.x + rect.width / 2,
                                            rect.y + rect.height / 2);
}
Exemple #29
0
static GSWindow *
find_window_at_pointer (GSManager *manager)
{
	GdkDisplay *display;
	GdkScreen  *screen;
	int         monitor;
	int         x, y;
	GSWindow   *window;
	int         screen_num;
	GSList     *l;

	display = gdk_display_get_default ();
	gdk_display_get_pointer (display, &screen, &x, &y, NULL);
	monitor = gdk_screen_get_monitor_at_point (screen, x, y);
	screen_num = gdk_screen_get_number (screen);

	/* Find the gs-window that is on that screen */
	window = NULL;
	for (l = manager->priv->windows; l; l = l->next)
	{
		GSWindow *win = GS_WINDOW (l->data);
		if (gs_window_get_screen (win) == screen
		        && gs_window_get_monitor (win) == monitor)
		{
			window = win;
		}
	}

	if (window == NULL)
	{
		gs_debug ("WARNING: Could not find the GSWindow for screen %d", screen_num);
		/* take the first one */
		window = manager->priv->windows->data;
	}
	else
	{
		gs_debug ("Requesting unlock for screen %d", screen_num);
	}

	return window;
}
static GtkArrowType get_notification_arrow_type(GtkWidget* nw)
{
	WindowData*     windata;
	GdkScreen*      screen;
	GdkRectangle    monitor_geometry;
	int             monitor;

	windata = g_object_get_data(G_OBJECT(nw), "windata");

	screen = gdk_window_get_screen(GDK_WINDOW( gtk_widget_get_window(nw)));
	monitor = gdk_screen_get_monitor_at_point(screen, windata->point_x, windata->point_y);
	gdk_screen_get_monitor_geometry(screen, monitor, &monitor_geometry);

	if (windata->point_y - monitor_geometry.y + windata->height + DEFAULT_ARROW_HEIGHT > monitor_geometry.height)
	{
		return GTK_ARROW_DOWN;
	}
	else
	{
		return GTK_ARROW_UP;
	}
}