// IM-2014-01-29: [[ HiDPI ]] Refactored to handle display info caching in MCUIDC superclass bool MCScreenDC::device_getdisplays(bool p_effective, MCDisplay * &r_displays, uint32_t &r_display_count) { // NOTE: this code assumes that there is only one GdkScreen! GdkScreen *t_screen; t_screen = gdk_display_get_default_screen(dpy); // Get the number of monitors attached to this screen gint t_monitor_count; t_monitor_count = gdk_screen_get_n_monitors(t_screen); // Allocate the list of monitors MCDisplay *t_displays; MCMemoryNewArray(t_monitor_count, t_displays); // Get the geometry of each monitor for (gint i = 0; i < t_monitor_count; i++) { GdkRectangle t_rect; gdk_screen_get_monitor_geometry(t_screen, i, &t_rect); MCRectangle t_mc_rect; t_mc_rect = MCRectangleMake(t_rect.x, t_rect.y, t_rect.width, t_rect.height); t_displays[i].index = i; t_displays[i].pixel_scale = 1.0; t_displays[i].viewport = t_displays[i].workarea = t_mc_rect; } if (t_monitor_count == 1) { apply_workarea(t_displays, t_monitor_count) || apply_partial_struts(t_displays, t_monitor_count); } else { apply_partial_struts(t_displays, t_monitor_count); } // All done r_displays = t_displays; r_display_count = t_monitor_count; return true; }
FloatRect screenRect(Widget* widget) { if (!widget) return FloatRect(); GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()); if (container) container = getToplevel(container); 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 geometry; gdk_screen_get_monitor_geometry(screen, monitor, &geometry); return FloatRect(geometry.x, geometry.y, geometry.width, geometry.height); }
static void ygtk_popup_window_frame_position (GtkWidget *widget, gint *x, gint *y) { // don't let it go outside the screen GtkRequisition req; gtk_widget_get_preferred_size(widget, &req, NULL); GdkScreen *screen = gtk_widget_get_screen (widget); gint monitor_num = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_root_window (widget)); GdkRectangle monitor; gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); if (*x < monitor.x) *x = monitor.x; else if (*x + req.width > monitor.x + monitor.width) *x = monitor.x + monitor.width - req.width; if (*y < monitor.y) *y = monitor.y; else if (*y + req.height > monitor.y + monitor.height) *y = monitor.y + monitor.height - req.height; }
// GTK doesn't centre the window correctly. Use this function to centre windows with a canvas that is yet to resized. void UI_centreCanvasWindow(GtkWindow *window, GtkWidget *canvas, int newCanvasWidth, int newCanvasHeight) { int winWidth, winHeight, widgetWidth, widgetHeight; GdkScreen *screen = gdk_screen_get_default(); int monitorNo = gdk_screen_get_monitor_at_window(screen, GTK_WIDGET(window->transient_parent)->window); GdkRectangle rect; gdk_screen_get_monitor_geometry(screen, monitorNo, &rect); gtk_widget_get_size_request((GtkWidget*)canvas, &widgetWidth, &widgetHeight); gtk_window_get_size(window, &winWidth, &winHeight); winWidth = newCanvasWidth; winHeight = (winHeight - widgetHeight) + newCanvasHeight; // Take borders and captions into consideration (GTK doesn't seem to support this so we'll have to guess) winWidth += 10; winHeight += 40; gtk_window_move(window, rect.x + (rect.width - winWidth) / 2, rect.y + (rect.height - winHeight) / 2); }
void calculate_position(Panel *np) { GdkScreen *screen; GdkRectangle marea; ENTER; /* FIXME: Why this doesn't work? */ /* if you are still going to use this, be sure to update it to take into account multiple monitors */ if (0) { // if (np->curdesk < np->wa_len/4) { marea.x = np->workarea[np->curdesk*4 + 0]; marea.y = np->workarea[np->curdesk*4 + 1]; marea.width = np->workarea[np->curdesk*4 + 2]; marea.height = np->workarea[np->curdesk*4 + 3]; } else { screen = gtk_widget_get_screen(np->topgwin); g_assert(np->monitor >= 0 && np->monitor < gdk_screen_get_n_monitors(screen)); gdk_screen_get_monitor_geometry(screen,np->monitor,&marea); } if (np->edge == EDGE_TOP || np->edge == EDGE_BOTTOM) { np->aw = np->width; np->ax = marea.x; calculate_width(marea.width, np->widthtype, np->allign, np->margin, &np->aw, &np->ax); np->ah = ((( ! np->autohide) || (np->visible)) ? np->height : np->height_when_hidden); np->ay = marea.y + ((np->edge == EDGE_TOP) ? 0 : (marea.height - np->ah)); } else { np->ah = np->width; np->ay = marea.y; calculate_width(marea.height, np->widthtype, np->allign, np->margin, &np->ah, &np->ay); np->aw = ((( ! np->autohide) || (np->visible)) ? np->height : np->height_when_hidden); np->ax = marea.x + ((np->edge == EDGE_LEFT) ? 0 : (marea.width - np->aw)); } //g_debug("%s - x=%d y=%d w=%d h=%d\n", __FUNCTION__, np->ax, np->ay, np->aw, np->ah); RET(); }
/* 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); }
static cairo_region_t * make_region_with_monitors (GdkScreen *screen) { cairo_region_t *region; int num_monitors; int i; num_monitors = gdk_screen_get_n_monitors (screen); region = cairo_region_create (); for (i = 0; i < num_monitors; i++) { GdkRectangle rect; gdk_screen_get_monitor_geometry (screen, i, &rect); cairo_region_union_rectangle (region, &rect); } return region; }
void FullscreenVideoControllerGtk::updateHudPosition() { if (!m_hudWindow) return; // Get the screen rectangle. GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(m_window)); GdkWindow* window = gtk_widget_get_window(m_window); GdkRectangle fullscreenRectangle; gdk_screen_get_monitor_geometry(screen, gdk_screen_get_monitor_at_window(screen, window), &fullscreenRectangle); // Get the popup window size. int hudWidth, hudHeight; gtk_window_get_size(GTK_WINDOW(m_hudWindow), &hudWidth, &hudHeight); // Resize the hud to the full width of the screen. gtk_window_resize(GTK_WINDOW(m_hudWindow), fullscreenRectangle.width, hudHeight); // Move the hud to the bottom of the screen. gtk_window_move(GTK_WINDOW(m_hudWindow), fullscreenRectangle.x, fullscreenRectangle.height + fullscreenRectangle.y - hudHeight); }
static void dma_data_view_goto_position_func (DmaDataView *view) { gint x, y; gint win_x, win_y; GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (view)); GdkScreen *screen = gdk_window_get_screen (window); gint monitor_num; GdkRectangle monitor; monitor_num = gdk_screen_get_monitor_at_window (screen, window); gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); gtk_widget_realize (view->goto_window); gdk_window_get_origin (window, &win_x, &win_y); x = MAX(12, win_x + 12); y = MAX(12, win_y + 12); gtk_window_move (GTK_WINDOW (view->goto_window), x, y); }
CMessagesDlg::CMessagesDlg(GtkWindow *pParent) { GtkWidget *text_view, *scrolled_window; GdkRectangle rc; // Dialog with buttons m_pDlg = gtk_dialog_new_with_buttons("Message log", pParent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, GTK_STOCK_HELP, GTK_RESPONSE_HELP, NULL); gtk_dialog_widget_standard_tooltips(GTK_DIALOG(m_pDlg)); g_signal_connect(G_OBJECT(m_pDlg), "response", G_CALLBACK(response_dialog), this); // Dialog size GdkScreen *scr = gtk_window_get_screen(pParent); int mon = gdk_screen_get_monitor_at_window(scr, GTK_WIDGET(pParent)->window); gdk_screen_get_monitor_geometry(scr, mon, &rc); if (rc.width>0 && rc.height>0) gtk_window_set_default_size(GTK_WINDOW(m_pDlg), RoundToInt(0.7*rc.width), RoundToInt(0.7*rc.height)); // Dialog icon gchar *icon = get_icon_file("messagelog"); gtk_window_set_icon(GTK_WINDOW(m_pDlg), gdk_pixbuf_new_from_file(icon, NULL)); g_free(icon); // List box text_view = gtk_text_view_new_with_buffer(ms_Buffer); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_WORD_CHAR); gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), false); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text_view), false); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(scrolled_window), text_view); gtk_widget_set_size_request(scrolled_window, 640, 480); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(m_pDlg)->vbox), scrolled_window, TRUE, TRUE, 0); gtk_widget_show_all(GTK_DIALOG(m_pDlg)->vbox); }
/** * 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); }
main (int argc, char *argv[]) { GOptionContext *context = NULL; GError *error = NULL; GdkScreen *screen; GdkRectangle rect; GnomeBG *bg; GSettings *settings; GdkPixbuf *pixbuf; gdk_init (&argc, &argv); context = g_option_context_new ("- refresh wallpaper cache"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s\n", error->message); g_option_context_free(context); g_error_free (error); return (1); } if (context) g_option_context_free (context); /* cache only the first monitor */ screen = gdk_screen_get_default (); gdk_screen_get_monitor_geometry (screen, 0, &rect); bg = gnome_bg_new (); settings = g_settings_new ("org.cinnamon.desktop.background"); gnome_bg_load_from_preferences (bg, settings); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, rect.width, rect.height); gnome_bg_draw (bg, pixbuf, screen, FALSE); g_object_unref (settings); return (0); }
/* panel_init */ static int _panel_init(Panel * panel, PanelWindowPosition position, PanelWindowType type, GtkIconSize iconsize) { const PanelPosition top = PANEL_POSITION_TOP; char * filename; GdkRectangle rect; size_t i; if((panel->config = config_new()) == NULL) return -1; if((filename = _config_get_filename()) != NULL && config_load(panel->config, filename) != 0) error_print(PROGNAME); free(filename); panel->prefs.iconsize = NULL; panel->prefs.monitor = -1; /* root window */ panel->screen = gdk_screen_get_default(); panel->root = gdk_screen_get_root_window(panel->screen); gdk_screen_get_monitor_geometry(panel->screen, 0, &rect); panel->root_height = rect.height; panel->root_width = rect.width; /* panel window */ _helper_init(&panel->helper[top], panel, type, iconsize); panel->windows[top] = panel_window_new(&panel->helper[top], PANEL_WINDOW_TYPE_NORMAL, position, iconsize, &rect); panel->helper[top].window = panel->windows[top]; for(i = 0; i < sizeof(panel->windows) / sizeof(*panel->windows); i++) if(i != top) panel->windows[i] = NULL; panel->source = 0; panel->timeout = 0; panel->ab_window = NULL; panel->lk_window = NULL; panel->lo_window = NULL; panel->sh_window = NULL; panel->su_window = NULL; return 0; }
static gint get_nearest_monitor (GdkScreen *screen, gint x, gint y) { gint num_monitors, i; gint nearest_dist = G_MAXINT; gint nearest_monitor = 0; num_monitors = gdk_screen_get_n_monitors (screen); for (i = 0; i < num_monitors; i++) { GdkRectangle monitor; gint dist_x, dist_y, dist; gdk_screen_get_monitor_geometry (screen, i, &monitor); if (x < monitor.x) dist_x = monitor.x - x; else if (x >= monitor.x + monitor.width) dist_x = x - (monitor.x + monitor.width) + 1; else dist_x = 0; if (y < monitor.y) dist_y = monitor.y - y; else if (y >= monitor.y + monitor.height) dist_y = y - (monitor.y + monitor.height) + 1; else dist_y = 0; dist = dist_x + dist_y; if (dist < nearest_dist) { nearest_dist = dist; nearest_monitor = i; } } return nearest_monitor; }
gboolean update_n_monitor_info(gint index,struct DisplayInfo* info) { GdkScreen* screen = gdk_screen_get_default(); if (screen == NULL) { return FALSE; } gint len = gdk_screen_get_n_monitors(screen); if (index > len - 1) { return FALSE; } GdkRectangle dest; gdk_screen_get_monitor_geometry(screen, index, &dest); info->x = dest.x; info->y = dest.y; info->width = dest.width; info->height = dest.height; info->index = index; g_message("[%s] gdk monitors num: %d, index: %d, %d*%d(%d,%d)\n", __func__, len, info->index, info->width, info->height, info->x, info->y); return TRUE; }
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; } }
void remmina_file_update_screen_resolution(RemminaFile *remminafile) { #if GTK_VERSION == 3 GdkDisplay *display; GdkDeviceManager *device_manager; GdkDevice *device; #endif 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) { #if GTK_VERSION == 3 display = gdk_display_get_default(); device_manager = gdk_display_get_device_manager(display); device = gdk_device_manager_get_client_pointer(device_manager); gdk_device_get_position(device, &screen, &x, &y); #elif GTK_VERSION == 2 gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, NULL); #endif 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); }
void gul_gui_sanitise_popup_position (GtkMenu *menu, GtkWidget *widget, gint *x, gint *y) { GdkScreen *screen = gtk_widget_get_screen (widget); gint monitor_num; GdkRectangle monitor; GtkRequisition req; g_return_if_fail (widget != NULL); gtk_widget_size_request (GTK_WIDGET (menu), &req); 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)); }
static void menu_position (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer entry) { GtkRequisition entry_request; GtkRequisition menu_request; GdkRectangle geometry; GdkScreen *screen; GtkWidget *toplevel = gtk_widget_get_toplevel (entry); gint monitor; gint x0; gint y0; gtk_widget_translate_coordinates (GTK_WIDGET (entry), toplevel, 0, 0, &x0, &y0); gtk_widget_size_request (GTK_WIDGET (entry), &entry_request); gtk_widget_size_request (GTK_WIDGET (menu), &menu_request); gdk_window_get_position (GTK_WIDGET (entry)->window, x, y); *x += x0 + gtk_container_get_border_width (GTK_CONTAINER (entry)); *y += y0 + (entry_request.height - gtk_container_get_border_width (GTK_CONTAINER (entry))); /* verify the the menu is on-screen */ screen = gtk_widget_get_screen (GTK_WIDGET (entry)); if (G_LIKELY (screen != NULL)) { monitor = gdk_screen_get_monitor_at_point (screen, *x, *y); gdk_screen_get_monitor_geometry (screen, monitor, &geometry); if (*y + menu_request.height > geometry.y + geometry.height) *y -= menu_request.height - entry_request.height; } *push_in = TRUE; }
static void gs_manager_create_window_for_monitor (GSManager *manager, GdkScreen *screen, int monitor) { GSWindow *window; GdkRectangle rect; gdk_screen_get_monitor_geometry (screen, monitor, &rect); gs_debug ("Creating window for monitor %d [%d,%d] (%dx%d)", monitor, rect.x, rect.y, rect.width, rect.height); window = gs_window_new (screen, monitor); connect_window_signals (manager, window); manager->priv->windows = g_slist_append (manager->priv->windows, window); if (manager->priv->active) { gtk_widget_show (GTK_WIDGET (window)); } }
void moth_gui::init_video() { GdkScreen *gdk_screen = gdk_screen_get_default(); int error = SDL_Init(SDL_INIT_VIDEO); if (error != SUCCESS || NULL == gdk_screen) { std::cerr<< "Video initialization failed: " << SDL_GetError( ) << std::endl; throw moth_bad_gui(); } int monitor = gdk_screen_get_primary_monitor(gdk_screen); GdkRectangle res; gdk_screen_get_monitor_geometry(gdk_screen, monitor, &res); const SDL_VideoInfo *info = SDL_GetVideoInfo(); if (!info) { std::cerr<< "Get Video info failed: " << SDL_GetError( ) << std::endl; throw moth_bad_gui(); } bpp = info->vfmt->BitsPerPixel; width = res.width; height = res.height; flags = SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_OPENGL | SDL_RESIZABLE; SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); screen = SDL_SetVideoMode(width, height, bpp, flags); if(NULL == screen) { std::cerr<< "Set Video Mode failed: " << SDL_GetError( ) << std::endl; throw moth_bad_gui(); } SDL_WM_SetCaption("moth - " MOTH_VER_STRING, NULL); init_opengl(); }
void idol_fullscreen_show_popups_or_osd (IdolFullscreen *fs, const char *icon_name, gboolean show_cursor) { GtkAllocation allocation; GdkScreen *screen; GdkWindow *window; GdkRectangle rect; int monitor; if (fs->priv->osd == NULL || icon_name == NULL) { idol_fullscreen_show_popups (fs, show_cursor); return; } gtk_widget_get_allocation (GTK_WIDGET (fs->priv->bvw), &allocation); gtk_window_resize (GTK_WINDOW (fs->priv->osd), allocation.height / 8, allocation.height / 8); window = gtk_widget_get_window (GTK_WIDGET (fs->priv->bvw)); screen = gtk_widget_get_screen (GTK_WIDGET (fs->priv->bvw)); monitor = gdk_screen_get_monitor_at_window (screen, window); gdk_screen_get_monitor_geometry (screen, monitor, &rect); if (gtk_widget_get_direction (GTK_WIDGET (fs->priv->bvw)) == GTK_TEXT_DIR_RTL) gtk_window_move (GTK_WINDOW (fs->priv->osd), rect.width - 8 - allocation.height / 8, rect.y + 8); else gtk_window_move (GTK_WINDOW (fs->priv->osd), rect.x + 8, rect.y + 8); gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (fs->priv->osd), icon_name, FALSE); gtk_widget_show (fs->priv->osd); }
void mdm_wm_screen_init (int cur_screen_num) { GdkScreen *screen; int i; if (g_getenv ("FAKE_XINERAMA_MDM") != NULL) { /* for testing Xinerama support on non-xinerama setups */ mdm_wm_screen.x = 100; mdm_wm_screen.y = 100; mdm_wm_screen.width = gdk_screen_width () / 2 - 100; mdm_wm_screen.height = gdk_screen_height () / 2 - 100; mdm_wm_allscreens = g_new0 (GdkRectangle, 2); mdm_wm_allscreens[0] = mdm_wm_screen; mdm_wm_allscreens[1].x = gdk_screen_width () / 2; mdm_wm_allscreens[1].y = gdk_screen_height () / 2; mdm_wm_allscreens[1].width = gdk_screen_width () / 2; mdm_wm_allscreens[1].height = gdk_screen_height () / 2; mdm_wm_screens = 2; return; } screen = gdk_screen_get_default (); mdm_wm_screens = gdk_screen_get_n_monitors (screen); mdm_wm_allscreens = g_new (GdkRectangle, mdm_wm_screens); for (i = 0; i < mdm_wm_screens; i++) gdk_screen_get_monitor_geometry (screen, i, mdm_wm_allscreens + i); if (mdm_wm_screens < cur_screen_num) cur_screen_num = 0; mdm_wm_screen = mdm_wm_allscreens[cur_screen_num]; }
void SetPos(CefWindowHandle handle, int x, int y, int width, int height) { GtkWindow* window = GetWindow(handle); GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window)); // Make sure the window isn't minimized or maximized. if (IsMaximized(window)) gtk_window_unmaximize(window); else gtk_window_present(window); // Retrieve information about the display that contains the window. GdkScreen* screen = gdk_screen_get_default(); gint monitor = gdk_screen_get_monitor_at_window(screen, gdk_window); GdkRectangle rect; gdk_screen_get_monitor_geometry(screen, monitor, &rect); // Make sure the window is inside the display. CefRect display_rect(rect.x, rect.y, rect.width, rect.height); CefRect window_rect(x, y, width, height); ModifyBounds(display_rect, window_rect); gdk_window_move_resize(gdk_window, window_rect.x, window_rect.y, window_rect.width, window_rect.height); }
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; wxGetWorkAreaX11(GDK_SCREEN_XSCREEN(screen), rect.x, rect.y, rect.width, rect.height); // in case _NET_WORKAREA result is too large gdk_rectangle_intersect(dest, &rect, dest); } #endif // GDK_WINDOWING_X11 } }
static void setup_tooltip_window_position(gpointer data, int w, int h) { int sig; int scr_w, scr_h, x, y, dy; #if GTK_CHECK_VERSION(2,2,0) int mon_num; GdkScreen *screen = NULL; #endif GdkRectangle mon_size; GtkWidget *tipwindow = pidgin_tooltip.tipwindow; #if GTK_CHECK_VERSION(2,2,0) 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; #else scr_w = gdk_screen_width(); scr_h = gdk_screen_height(); gdk_window_get_pointer(NULL, &x, &y, NULL); mon_size.x = 0; mon_size.y = 0; #endif #if GTK_CHECK_VERSION(2,4,0) dy = gdk_display_get_default_cursor_size(gdk_display_get_default()) / 2; #else dy = 0; #endif #if GTK_CHECK_VERSION(2,2,0) if (w > mon_size.width) w = mon_size.width - 10; if (h > mon_size.height) h = mon_size.height - 10; #endif 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)); }
static gboolean gtk_scale_popup (GtkWidget *widget, GdkEvent *event, guint32 time) { GtkScaleButton *button; GtkScaleButtonPrivate *priv; GtkAdjustment *adj; gint x, y, m, dx, dy, sx, sy, startoff; gdouble v; GdkDisplay *display; GdkScreen *screen; button = GTK_SCALE_BUTTON (widget); priv = button->priv; adj = priv->adjustment; display = gtk_widget_get_display (widget); screen = gtk_widget_get_screen (widget); /* position roughly */ gtk_window_set_screen (GTK_WINDOW (priv->dock), screen); gdk_window_get_origin (widget->window, &x, &y); x += widget->allocation.x; y += widget->allocation.y; if (priv->orientation == GTK_ORIENTATION_VERTICAL) gtk_window_move (GTK_WINDOW (priv->dock), x, y - (SCALE_SIZE / 2)); else gtk_window_move (GTK_WINDOW (priv->dock), x - (SCALE_SIZE / 2), y); gtk_widget_show_all (priv->dock); gdk_window_get_origin (priv->dock->window, &dx, &dy); dx += priv->dock->allocation.x; dy += priv->dock->allocation.y; gdk_window_get_origin (priv->scale->window, &sx, &sy); sx += priv->scale->allocation.x; sy += priv->scale->allocation.y; priv->timeout = TRUE; /* position (needs widget to be shown already) */ v = gtk_scale_button_get_value (button) / (adj->upper - adj->lower); if (priv->orientation == GTK_ORIENTATION_VERTICAL) { startoff = sy - dy; x += (widget->allocation.width - priv->dock->allocation.width) / 2; y -= startoff; y -= GTK_RANGE (priv->scale)->min_slider_size / 2; m = priv->scale->allocation.height - GTK_RANGE (priv->scale)->min_slider_size; y -= m * (1.0 - v); } else { startoff = sx - dx; x -= startoff; y += (widget->allocation.height - priv->dock->allocation.height) / 2; x -= GTK_RANGE (priv->scale)->min_slider_size / 2; m = priv->scale->allocation.width - GTK_RANGE (priv->scale)->min_slider_size; x -= m * v; } /* Make sure the dock stays inside the monitor */ if (event->type == GDK_BUTTON_PRESS) { int monitor; GdkEventButton *button_event = (GdkEventButton *) event; GdkRectangle rect; GtkWidget *d; d = GTK_WIDGET (priv->dock); monitor = gdk_screen_get_monitor_at_point (screen, button_event->x_root, button_event->y_root); gdk_screen_get_monitor_geometry (screen, monitor, &rect); if (priv->orientation == GTK_ORIENTATION_VERTICAL) y += button_event->y; else x += button_event->x; if (y < rect.y) y = rect.y; else if (y + d->allocation.height > rect.height + rect.y) y = rect.y + rect.height - d->allocation.height; if (x < rect.x) x = rect.x; else if (x + d->allocation.width > rect.width + rect.x) x = rect.x + rect.width - d->allocation.width; } gtk_window_move (GTK_WINDOW (priv->dock), x, y); if (event->type == GDK_BUTTON_PRESS) GTK_WIDGET_CLASS (gtk_scale_button_parent_class)->button_press_event (widget, (GdkEventButton *) event); /* grab focus */ gtk_grab_add (priv->dock); if (gdk_pointer_grab (priv->dock->window, TRUE, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, time) != GDK_GRAB_SUCCESS) { gtk_grab_remove (priv->dock); gtk_widget_hide (priv->dock); return FALSE; } if (gdk_keyboard_grab (priv->dock->window, TRUE, time) != GDK_GRAB_SUCCESS) { gdk_display_pointer_ungrab (display, time); gtk_grab_remove (priv->dock); gtk_widget_hide (priv->dock); return FALSE; } gtk_widget_grab_focus (priv->dock); if (event->type == GDK_BUTTON_PRESS) { GdkEventButton *e; GdkEventButton *button_event = (GdkEventButton *) event; /* forward event to the slider */ e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event); e->window = priv->scale->window; /* position: the X position isn't relevant, halfway will work just fine. * The vertical position should be *exactly* in the middle of the slider * of the scale; if we don't do that correctly, it'll move from its current * position, which means a position change on-click, which is bad. */ if (priv->orientation == GTK_ORIENTATION_VERTICAL) { e->x = priv->scale->allocation.width / 2; m = priv->scale->allocation.height - GTK_RANGE (priv->scale)->min_slider_size; e->y = ((1.0 - v) * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; } else { e->y = priv->scale->allocation.height / 2; m = priv->scale->allocation.width - GTK_RANGE (priv->scale)->min_slider_size; e->x = (v * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; } gtk_widget_event (priv->scale, (GdkEvent *) e); e->window = button_event->window; gdk_event_free ((GdkEvent *) e); } gtk_widget_grab_focus (priv->scale); priv->pop_time = time; return TRUE; }
static void notify_stack_shift_notifications (NotifyStack *stack, GtkWindow *nw, GList **nw_l, gint init_width, gint init_height, gint *nw_x, gint *nw_y) { GdkRectangle workarea; GdkRectangle monitor; GdkRectangle *positions; GList *l; gint x, y; gint shiftx = 0; gint shifty = 0; int i; int n_wins; get_work_area (stack, &workarea); gdk_screen_get_monitor_geometry (stack->screen, stack->monitor, &monitor); gdk_rectangle_intersect (&monitor, &workarea, &workarea); add_padding_to_rect (&workarea); n_wins = g_list_length (stack->windows); positions = g_new0 (GdkRectangle, n_wins); get_origin_coordinates (stack->location, &workarea, &x, &y, &shiftx, &shifty, init_width, init_height); if (nw_x != NULL) *nw_x = x; if (nw_y != NULL) *nw_y = y; for (i = 0, l = stack->windows; l != NULL; i++, l = l->next) { GtkWindow *nw2 = GTK_WINDOW (l->data); GtkRequisition req; if (nw == NULL || nw2 != nw) { gtk_widget_size_request (GTK_WIDGET (nw2), &req); translate_coordinates (stack->location, &workarea, &x, &y, &shiftx, &shifty, req.width, req.height + NOTIFY_STACK_SPACING); positions[i].x = x; positions[i].y = y; } else if (nw_l != NULL) { *nw_l = l; positions[i].x = -1; positions[i].y = -1; } } /* move bubbles at the bottom of the stack first to avoid overlapping */ for (i = n_wins - 1, l = g_list_last (stack->windows); l != NULL; i--, l = l->prev) { GtkWindow *nw2 = GTK_WINDOW (l->data); if (nw == NULL || nw2 != nw) { theme_move_notification (nw2, positions[i].x, positions[i].y); } } g_free (positions); }
Geometry pMonitor::geometry(unsigned monitor) { GdkRectangle rectangle = {0}; gdk_screen_get_monitor_geometry(gdk_screen_get_default(), monitor, &rectangle); return {rectangle.x, rectangle.y, rectangle.width, rectangle.height}; }
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; }