void cheese_flash_fire (CheeseFlash *flash) { CheeseFlashPrivate *flash_priv = CHEESE_FLASH_GET_PRIVATE (flash); GtkWidget *parent; GdkScreen *screen; GdkRectangle rect; int monitor; g_return_if_fail (flash_priv->parent != NULL); GtkWindow *flash_window = flash_priv->window; 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); 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); }
static void ephy_fullscreen_popup_update_position (EphyFullscreenPopup *popup) { GtkWidget *widget = GTK_WIDGET (popup); GtkRequisition requisition; GdkScreen *screen; GdkRectangle screen_rect; int popup_width; gtk_widget_get_preferred_size (widget, &requisition, NULL); popup_width = requisition.width; screen = gtk_widget_get_screen (widget); gdk_screen_get_monitor_geometry (screen, gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (widget)), &screen_rect); if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) { gtk_window_move (GTK_WINDOW (widget), screen_rect.x, screen_rect.y); } else { gtk_window_move (GTK_WINDOW (widget), screen_rect.x + screen_rect.width - popup_width, screen_rect.y); } }
gboolean totem_ratio_fits_screen (GdkWindow * video_window, int video_width, int video_height, gfloat ratio) { GdkRectangle fullscreen_rect; int new_w, new_h; GdkScreen *screen; if (video_width <= 0 || video_height <= 0) return TRUE; new_w = video_width * ratio; new_h = video_height * ratio; screen = gdk_drawable_get_screen (GDK_DRAWABLE (video_window)); gdk_screen_get_monitor_geometry (screen, gdk_screen_get_monitor_at_window (screen, video_window), &fullscreen_rect); if (new_w > (fullscreen_rect.width - 128) || new_h > (fullscreen_rect.height - 128)) { return FALSE; } return TRUE; }
static void apply_background_to_window (GSManager *manager, GSWindow *window) { cairo_surface_t *surface = NULL; GdkScreen *screen; GdkWindow *gdk_window; gint monitor; GdkRectangle monitor_geometry; int width; int height; // if (manager->priv->bg == NULL) { // gs_debug ("No background available"); gs_window_set_background_surface (window, NULL); //} screen = gs_window_get_screen (window); gdk_window = gs_window_get_gdk_window (window); monitor = gdk_screen_get_monitor_at_window (screen, gdk_window); gdk_screen_get_monitor_geometry (screen, monitor, &monitor_geometry); width = monitor_geometry.width; height = monitor_geometry.height; gs_debug ("Creating background w:%d h:%d", width, height); /*surface = gnome_bg_create_surface (manager->priv->bg, gdk_window, width, height, FALSE);*/ gs_window_set_background_surface (window, surface); cairo_surface_destroy (surface); }
static void request (GtkWidget *widget, gpointer user_data) { gchar *str; GdkScreen *screen = gtk_widget_get_screen (widget); gint i = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (widget)); if (i < 0) str = g_strdup ("<big><span foreground='white' background='black'>Not on a monitor </span></big>"); else { GdkRectangle monitor; gdk_screen_get_monitor_geometry (screen, i, &monitor); primary_monitor = gdk_screen_get_primary_monitor (screen); str = g_strdup_printf ("<big><span foreground='white' background='black'>" "Monitor %d of %d</span></big>\n" "<i>Width - Height </i>: (%d,%d)\n" "<i>Top left coordinate </i>: (%d,%d)\n" "<i>Primary monitor: %d</i>", i + 1, num_monitors, monitor.width, monitor.height, monitor.x, monitor.y, primary_monitor); } gtk_label_set_markup (GTK_LABEL (user_data), str); g_free (str); }
static GdkScreen * cdisplay_lcms_get_screen (CdisplayLcms *lcms, gint *monitor) { GimpColorManaged *managed; GdkScreen *screen; managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms)); if (GTK_IS_WIDGET (managed)) screen = gtk_widget_get_screen (GTK_WIDGET (managed)); else screen = gdk_screen_get_default (); g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); if (GTK_IS_WIDGET (managed) && gtk_widget_get_window (GTK_WIDGET (managed))) { GtkWidget *widget = GTK_WIDGET (managed); *monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (widget)); } else { *monitor = 0; } return screen; }
static void emoticon_tool_button_reposition_window (EEmoticonToolButton *button) { GdkScreen *screen; GdkWindow *window; GdkRectangle monitor; GtkAllocation allocation; gint monitor_num; gint x, y, width, height; screen = gtk_widget_get_screen (GTK_WIDGET (button)); window = gtk_widget_get_window (GTK_WIDGET (button)); monitor_num = gdk_screen_get_monitor_at_window (screen, window); gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); gdk_window_get_origin (window, &x, &y); if (!gtk_widget_get_has_window (GTK_WIDGET (button))) { gtk_widget_get_allocation (GTK_WIDGET (button), &allocation); x += allocation.x; y += allocation.y; } gtk_widget_get_allocation (button->priv->window, &allocation); width = allocation.width; height = allocation.height; x = CLAMP (x, monitor.x, monitor.x + monitor.width - width); y = CLAMP (y, monitor.y, monitor.y + monitor.height - height); gtk_window_move (GTK_WINDOW (button->priv->window), x, y); }
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; }
static void menu_position_func (GtkMenu * menu, gint * x, gint * y, gboolean* push_in, gpointer user_data) { GtkRequisition requisition; GtkAllocation allocation; GdkRectangle monitor_geometry; GdkScreen * screen; int monitor; screen = gtk_widget_get_screen (GTK_WIDGET (menu)); gtk_widget_get_allocation (user_data, &allocation); gtk_widget_size_request (GTK_WIDGET (menu), &requisition); gdk_window_get_root_coords (gtk_widget_get_parent_window (user_data), allocation.x, allocation.y, &allocation.x, &allocation.y); monitor = gdk_screen_get_monitor_at_window (screen, GTK_WIDGET (user_data)->window); gtk_menu_set_monitor (menu, monitor); gdk_screen_get_monitor_geometry (screen, monitor, &monitor_geometry); if (allocation.y >= monitor_geometry.y && allocation.y + allocation.height + requisition.height <= monitor_geometry.y + monitor_geometry.height) { *y = allocation.y + allocation.height; } else if (allocation.y - requisition.height >= monitor_geometry.y && allocation.y <= monitor_geometry.y + monitor_geometry.height) { *y = allocation.y - requisition.height; } else { g_warning ("implement menu somewhere else"); *y = allocation.y; } switch (gtk_widget_get_direction (user_data)) { case GTK_TEXT_DIR_RTL: *x = allocation.x + allocation.width - requisition.width; break; case GTK_TEXT_DIR_LTR: case GTK_TEXT_DIR_NONE: *x = allocation.x; break; default: g_warn_if_reached (); *x = allocation.x; break; } }
static void attachment_button_menu_position (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, EAttachmentButton *button) { GtkRequisition menu_requisition; GtkTextDirection direction; GtkAllocation allocation; GdkRectangle monitor; GdkScreen *screen; GdkWindow *window; GtkWidget *widget; GtkWidget *toggle_button; gint monitor_num; widget = GTK_WIDGET (button); toggle_button = button->priv->toggle_button; gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_requisition, NULL); window = gtk_widget_get_parent_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_geometry (screen, monitor_num, &monitor); gtk_widget_get_allocation (widget, &allocation); gdk_window_get_origin (window, x, y); *x += allocation.x; *y += allocation.y; direction = gtk_widget_get_direction (widget); if (direction == GTK_TEXT_DIR_LTR) *x += MAX (allocation.width - menu_requisition.width, 0); else if (menu_requisition.width > allocation.width) *x -= menu_requisition.width - allocation.width; gtk_widget_get_allocation (toggle_button, &allocation); if ((*y + allocation.height + menu_requisition.height) <= monitor.y + monitor.height) *y += allocation.height; else if ((*y - menu_requisition.height) >= monitor.y) *y -= menu_requisition.height; else if (monitor.y + monitor.height - (*y + allocation.height) > *y) *y += allocation.height; else *y -= menu_requisition.height; *push_in = FALSE; }
static void menu_position_under_widget (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data) { GtkWidget *widget; GtkWidget *container; GtkRequisition req; GtkRequisition menu_req; GdkRectangle monitor; int monitor_num; GdkScreen *screen; widget = GTK_WIDGET (user_data); g_assert (GTK_IS_WIDGET (widget)); container = gtk_widget_get_ancestor (widget, GTK_TYPE_CONTAINER); g_assert (container != NULL); gtk_widget_size_request (widget, &req); gtk_widget_size_request (GTK_WIDGET (menu), &menu_req); screen = gtk_widget_get_screen (GTK_WIDGET (menu)); monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window); if (monitor_num < 0) { monitor_num = 0; } gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); gdk_window_get_origin (widget->window, x, y); if (GTK_WIDGET_NO_WINDOW (widget)) { *x += widget->allocation.x; *y += widget->allocation.y; } if (gtk_widget_get_direction (container) == GTK_TEXT_DIR_LTR) { *x += widget->allocation.width - req.width; } else { *x += req.width - menu_req.width; } if ((*y + widget->allocation.height + menu_req.height) <= monitor.y + monitor.height) { *y += widget->allocation.height; } else if ((*y - menu_req.height) >= monitor.y) { *y -= menu_req.height; } else if (monitor.y + monitor.height - (*y + widget->allocation.height) > *y) { *y += widget->allocation.height; } else { *y -= menu_req.height; } *push_in = FALSE; }
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"); } }
/* makes the menu appear next to the widget [user_data] * instead off right under the cursor */ static void position_menu ( GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data) { GtkWidget *widget = GTK_WIDGET (user_data); GdkScreen *screen; gint twidth, theight, tx, ty; GtkTextDirection direction; GdkRectangle monitor; gint monitor_num; g_return_if_fail (menu != NULL); g_return_if_fail (x != NULL); g_return_if_fail (y != NULL); if (push_in) *push_in = FALSE; direction = gtk_widget_get_direction (widget); twidth = GTK_WIDGET (menu)->requisition.width; theight = GTK_WIDGET (menu)->requisition.height; screen = gtk_widget_get_screen (GTK_WIDGET (menu)); monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window); if (monitor_num < 0) monitor_num = 0; gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); if (!gdk_window_get_origin (widget->window, &tx, &ty)) { g_warning ("Menu not on screen"); return; } tx += widget->allocation.x; ty += widget->allocation.y; if (direction == GTK_TEXT_DIR_RTL) tx += widget->allocation.width - twidth; if ((ty + widget->allocation.height + theight) <= monitor.y + monitor.height) ty += widget->allocation.height; else if ((ty - theight) >= monitor.y) ty -= theight; else if (monitor.y + monitor.height - (ty + widget->allocation.height) > ty) ty += widget->allocation.height; else ty -= theight; *x = CLAMP (tx, monitor.x, MAX (monitor.x, monitor.x + monitor.width - twidth)); *y = ty; gtk_menu_set_monitor (menu, monitor_num); }
/* 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; }
static void nsp_window_realize(GtkWidget *widget, NspWindow *win) { GdkScreen *screen; GdkRectangle monitor; screen = gtk_window_get_screen (GTK_WINDOW(widget)); gdk_screen_get_monitor_geometry (screen, gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window(widget)), &monitor); gtk_window_set_default_size(GTK_WINDOW(widget), monitor.width * 0.9 - 100, monitor.height * 0.9 - 100); gtk_widget_set_size_request(GTK_WIDGET(gtk_builder_get_object(win->builder, "feed_item_list_win")), -1, (monitor.height * 0.9 - 100)/4); }
static gdouble get_monitor_aspect_ratio_for_widget (GtkWidget *widget) { gdouble aspect; gint monitor; GdkRectangle rect; monitor = gdk_screen_get_monitor_at_window (gtk_widget_get_screen (widget), gtk_widget_get_window (widget)); gdk_screen_get_monitor_geometry (gtk_widget_get_screen (widget), monitor, &rect); aspect = rect.height / (gdouble)rect.width; return aspect; }
static gboolean matenu_global_menu_item_sync_monitor_num (MatenuGlobalMenuItem* self) { gboolean result = FALSE; GdkScreen* screen; g_return_val_if_fail (self != NULL, FALSE); screen = _g_object_ref0 (gtk_widget_get_screen ((GtkWidget*) self)); if (GTK_WIDGET_REALIZED ((GtkWidget*) self)) { matenu_monitor_set_monitor_num (self->priv->active_window_monitor, gdk_screen_get_monitor_at_window (screen, ((GtkWidget*) self)->window)); } else { matenu_monitor_set_monitor_num (self->priv->active_window_monitor, -1); } result = FALSE; _g_object_unref0 (screen); return result; }
// // Open preview in standalone window // void CPreview::ShowFileModal(void) { GdkRectangle rc; char buf[FILENAME_MAX+128]; GtkWindow *pParent = GTK_WINDOW(GetTopLevel()); if (m_FileType!=TYPE_IMAGE && m_FileType!=TYPE_CAT && m_FileType!=TYPE_PHOT && m_FileType!=TYPE_TABLE) return; // Dialog with buttons GtkWidget *pDlg = gtk_dialog_new_with_buttons("", pParent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); gtk_dialog_widget_standard_tooltips(GTK_DIALOG(pDlg)); // 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(pDlg), RoundToInt(0.7*rc.width), RoundToInt(0.7*rc.height)); // Dialog icon char *icon = get_icon_file("preview"); gtk_window_set_icon(GTK_WINDOW(pDlg), gdk_pixbuf_new_from_file(icon, NULL)); g_free(icon); // Preview widget GtkWidget *preview = cmpack_preview_new_with_model(m_Data); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pDlg)->vbox), preview, TRUE, TRUE, 0); if (m_FileType == TYPE_TABLE) { cmpack_preview_set_x_axis(CMPACK_PREVIEW(preview), FALSE, FALSE, m_MinX, m_MaxX, m_EpsX); cmpack_preview_set_y_axis(CMPACK_PREVIEW(preview), FALSE, m_ReverseY, m_MinY, m_MaxY, m_EpsY); } bool chart_invert = CConfig::GetBool(CConfig::NEGATIVE_CHARTS); cmpack_preview_set_negative(CMPACK_PREVIEW(preview), chart_invert); bool rows_upward = CConfig::GetBool(CConfig::ROWS_UPWARD); cmpack_preview_set_image_orientation(CMPACK_PREVIEW(preview), rows_upward ? CMPACK_ROWS_UPWARDS : CMPACK_ROWS_DOWNWARDS); // Display the preview dialog gchar *basename = g_path_get_basename(m_Path); sprintf(buf, "%s - %s", basename, g_AppTitle); g_free(basename); gtk_window_set_title(GTK_WINDOW(pDlg), buf); gtk_widget_show_all(pDlg); gtk_dialog_run(GTK_DIALOG(pDlg)); gtk_widget_destroy(pDlg); }
static void xplayer_fullscreen_move_popups (XplayerFullscreen *fs) { int exit_width, exit_height; int control_width, control_height; GdkScreen *screen; GdkRectangle fullscreen_rect; GdkWindow *window; XplayerFullscreenPrivate *priv = fs->priv; g_return_if_fail (priv->parent_window != NULL); /* Obtain the screen rectangle */ screen = gtk_window_get_screen (GTK_WINDOW (priv->parent_window)); window = gtk_widget_get_window (priv->parent_window); gdk_screen_get_monitor_geometry (screen, gdk_screen_get_monitor_at_window (screen, window), &fullscreen_rect); /* Get the popup window sizes */ gtk_window_get_size (GTK_WINDOW (priv->exit_popup), &exit_width, &exit_height); gtk_window_get_size (GTK_WINDOW (priv->control_popup), &control_width, &control_height); /* We take the full width of the screen */ gtk_window_resize (GTK_WINDOW (priv->control_popup), fullscreen_rect.width, control_height); if (gtk_widget_get_direction (priv->exit_popup) == GTK_TEXT_DIR_RTL) { gtk_window_move (GTK_WINDOW (priv->exit_popup), fullscreen_rect.x, fullscreen_rect.y); gtk_window_move (GTK_WINDOW (priv->control_popup), fullscreen_rect.width - control_width, fullscreen_rect.height + fullscreen_rect.y - control_height); } else { gtk_window_move (GTK_WINDOW (priv->exit_popup), fullscreen_rect.width + fullscreen_rect.x - exit_width, fullscreen_rect.y); gtk_window_move (GTK_WINDOW (priv->control_popup), fullscreen_rect.x, fullscreen_rect.height + fullscreen_rect.y - control_height); } }
static void scrolled_realize_cb (GtkWidget *scrolled, CcBackgroundPanel *self) { /* FIXME, hack for https://bugzilla.gnome.org/show_bug.cgi?id=645649 */ GdkScreen *screen; GdkRectangle rect; int monitor; screen = gtk_widget_get_screen (scrolled); monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (scrolled)); gdk_screen_get_monitor_geometry (screen, monitor, &rect); if (rect.height <= 768) g_object_set (G_OBJECT (scrolled), "height-request", 280, NULL); }
static void tab_completion_popup_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) { TabCompData *td = data; gint height; PangoLayout *layout; PangoRectangle strong_pos, weak_pos; gint length; gint xoffset, yoffset; GtkRequisition req; GdkScreen *screen; gint monitor_num; GdkRectangle monitor; GtkRequisition requisition; GtkAllocation allocation; gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(td->entry)), x, y); screen = gtk_widget_get_screen(GTK_WIDGET(menu)); monitor_num = gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(GTK_WIDGET(td->entry))); gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor); gtk_widget_size_request(GTK_WIDGET(menu), &req); length = strlen(gtk_entry_get_text(GTK_ENTRY(td->entry))); gtk_entry_get_layout_offsets(GTK_ENTRY(td->entry), &xoffset, &yoffset); layout = gtk_entry_get_layout(GTK_ENTRY(td->entry)); pango_layout_get_cursor_pos(layout, length, &strong_pos, &weak_pos); *x += strong_pos.x / PANGO_SCALE + xoffset; gtk_widget_get_requisition(td->entry, &requisition); gtk_widget_get_allocation(td->entry, &allocation); height = MIN(requisition.height, allocation.height); if (req.height > monitor.y + monitor.height - *y - height && *y - monitor.y > monitor.y + monitor.height - *y) { height = MIN(*y - monitor.y, req.height); gtk_widget_set_size_request(GTK_WIDGET(menu), -1, height); *y -= height; } else { *y += height; } }
void rb_visualizer_fullscreen_add_widgets (GtkWidget *window, ClutterActor *stage, RBShell *shell) { ClutterActor *track_info; ClutterActor *controls; GdkScreen *screen; GdkRectangle geom; int x; int y; int monitor; clutter_threads_enter (); /* get geometry for the monitor we're going to appear on */ screen = gtk_widget_get_screen (window); monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (window)); gdk_screen_get_monitor_geometry (screen, monitor, &geom); /* create and place the track info display */ track_info = create_track_info (shell); clutter_container_add_actor (CLUTTER_CONTAINER (stage), track_info); g_object_set_data (G_OBJECT (stage), TRACK_INFO_DATA, track_info); /* XXX rtl? */ clutter_actor_set_position (track_info, FULLSCREEN_BORDER_WIDTH, FULLSCREEN_BORDER_WIDTH); /* create and place the playback controls */ controls = create_controls (shell); clutter_container_add_actor (CLUTTER_CONTAINER (stage), controls); g_object_set_data (G_OBJECT (stage), CONTROLS_DATA, controls); /* put this bit somewhere near the bottom */ /* XXX rtl */ x = FULLSCREEN_BORDER_WIDTH; y = geom.height - (clutter_actor_get_height (controls) + FULLSCREEN_BORDER_WIDTH); clutter_actor_set_position (controls, x, y); /* hide mouse cursor when not moving, hide playback controls when mouse not moving * and outside them */ g_signal_connect_object (stage, "motion-event", G_CALLBACK (stage_motion_event_cb), controls, 0); g_signal_connect (controls, "leave-event", G_CALLBACK (controls_leave_event_cb), NULL); g_signal_connect (controls, "enter-event", G_CALLBACK (controls_enter_event_cb), NULL); start_hide_timer (controls); clutter_threads_leave (); }
static void popup_button_position (PlannerPopupButton *button, gint *x, gint *y) { PlannerPopupButtonPriv *priv; GtkWidget *button_widget; GtkRequisition popup_req; GdkScreen *screen; gint monitor_num; GdkRectangle monitor; priv = GET_PRIV (button); button_widget = GTK_WIDGET (button); gdk_window_get_origin (button_widget->window, x, y); if (! gtk_widget_get_has_window (button_widget)) { *x += button_widget->allocation.x; *y += button_widget->allocation.y; } /* The popup should be placed below the button, right-aligned to it. */ *y += button_widget->allocation.height; *x += button_widget->allocation.width; gtk_widget_size_request (priv->popup_widget, &popup_req); *x -= popup_req.width; /* Don't popup outside the monitor edges. */ screen = gtk_widget_get_screen (GTK_WIDGET (button)); monitor_num = gdk_screen_get_monitor_at_window ( screen, GTK_WIDGET (button)->window); gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); if (*x < monitor.x) { *x = monitor.x; } else if (*x + popup_req.width > monitor.x + monitor.width) { *x = monitor.x + monitor.width - popup_req.width; } if (*y + popup_req.height > monitor.y + monitor.height) { *y -= popup_req.height + button_widget->allocation.height; } }
FloatRect screenRect(Widget* widget) { GtkWidget* container = gtk_widget_get_toplevel(GTK_WIDGET(widget->root()->hostWindow()->platformWindow())); if (!GTK_WIDGET_TOPLEVEL(container)) return FloatRect(); GdkScreen* screen = gtk_widget_has_screen(container) ? gtk_widget_get_screen(container) : gdk_screen_get_default(); if (!screen) return FloatRect(); gint monitor = gdk_screen_get_monitor_at_window(screen, GTK_WIDGET(container)->window); GdkRectangle geometry; gdk_screen_get_monitor_geometry(screen, monitor, &geometry); return FloatRect(geometry.x, geometry.y, geometry.width, geometry.height); }
FloatRect screenRect(Widget* widget) { GtkWidget* container = GTK_WIDGET(widget->containingWindow()); if (!container) return FloatRect(); GdkScreen* screen = gtk_widget_has_screen(container) ? gtk_widget_get_screen(container) : gdk_screen_get_default(); if (!screen) return FloatRect(); gint monitor = gdk_screen_get_monitor_at_window(screen, GTK_WIDGET(container)->window); GdkRectangle geometry; gdk_screen_get_monitor_geometry(screen, monitor, &geometry); return FloatRect(geometry.x, geometry.y, geometry.width, geometry.height); }
void _gtk_widget_get_screen_size (GtkWidget *widget, int *width, int *height) { GdkScreen *screen; GdkRectangle screen_geom; screen = gtk_widget_get_screen (widget); gdk_screen_get_monitor_geometry (screen, gdk_screen_get_monitor_at_window (screen, widget->window), &screen_geom); *width = screen_geom.width; *height = screen_geom.height; }
FloatRect screenRect(Widget* widget) { GtkWidget* container = widget ? GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()) : 0; 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); }
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 set_window_default_size (GdictApplet *applet) { GdictAppletPrivate *priv = applet->priv; GtkWidget *widget, *defbox; gint width, height; gint font_size; GdkScreen *screen; gint monitor_num; GtkRequisition req; GdkRectangle monitor; if (!priv->window) return; widget = priv->window; defbox = priv->defbox; /* Size based on the font size */ font_size = pango_font_description_get_size (gtk_widget_get_style (defbox)->font_desc); font_size = PANGO_PIXELS (font_size); width = font_size * WINDOW_NUM_COLUMNS; height = font_size * WINDOW_NUM_ROWS; /* Use at least the requisition size of the window... */ gtk_widget_size_request (widget, &req); width = MAX (width, req.width); height = MAX (height, req.height); /* ... but make it no larger than half the monitor size */ screen = gtk_widget_get_screen (widget); monitor_num = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (widget)); gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); width = MIN (width, monitor.width / 2); height = MIN (height, monitor.height / 2); /* Set size */ gtk_widget_set_size_request (priv->frame, width, 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); }