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); }
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; }
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); }
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); }
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 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; }
gboolean hippo_ui_get_pointer_position (HippoUI *ui, int *x_p, int *y_p) { GdkScreen *screen; GdkScreen *pointer_screen; int x, y; gtk_status_icon_get_geometry(GTK_STATUS_ICON(ui->icon), &screen, NULL, NULL); gdk_display_get_pointer(gdk_screen_get_display(screen), &pointer_screen, &x, &y, NULL); if (pointer_screen != screen) { x = 0; y = 0; } if (x_p) *x_p = x; if (y_p) *y_p = y; return pointer_screen == screen; }
/* static */ guint KeymapWrapper::GetCurrentModifierState() { GdkModifierType modifiers; gdk_display_get_pointer(gdk_display_get_default(), NULL, NULL, NULL, &modifiers); return static_cast<guint>(modifiers); }
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)); }
static void receiver_func(GtkClipboard *clipboard, const gchar *text, gpointer data) { /* * defer if still in selection */ GdkModifierType modifier; GdkDisplay *display = gdk_display_get_default(); gdk_display_get_pointer(display, NULL, NULL, NULL, &modifier); if (modifier & GDK_BUTTON1_MASK) { rearm = TRUE; return; } /* * some program deselection text will send NULL text! */ if (!text) { if (recv_text) { g_free(recv_text); recv_text = NULL; } rearm = TRUE; return; } /* discard it if too big! (> 32 seems bigger!) */ if (strlen(text) > 32) { rearm = TRUE; return; } if (recv_text && strcmp(recv_text, text) == 0) { rearm = TRUE; return; } if (recv_text) { g_free(recv_text); recv_text = NULL; } if (text && text[0]) recv_text = g_strdup(text); if (recv_text) { gchar *context = fd_utils_get_active_window_title(); if (context && strcmp(context, "Run Program...") == 0) { /* ignore xfce's "Run Program..." dialog */ } else { fd_stage_show(recv_text, context); } g_free(context); } rearm = TRUE; }
/** * Function that tracks the mouse pointer on the screen * * @param widget * @return */ static gboolean time_handler( GtkWidget *widget) { GdkDisplay *pDisplay = gdk_display_get_default (); /* get cursor position */ int iX,iY; gdk_display_get_pointer(pDisplay, NULL, &iX, &iY, NULL); printf("X:%d Y:%d\n",iX,iY); return TRUE; }
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; }
/** * shell_global_get_pointer: * @global: the #ShellGlobal * @x: (out): the X coordinate of the pointer, in global coordinates * @y: (out): the Y coordinate of the pointer, in global coordinates * @mods: (out): the current set of modifier keys that are pressed down * * Gets the pointer coordinates and current modifier key state. * This is a wrapper around gdk_display_get_pointer() that strips * out any un-declared modifier flags, to make gjs happy; see * https://bugzilla.gnome.org/show_bug.cgi?id=597292. */ void shell_global_get_pointer (ShellGlobal *global, int *x, int *y, ClutterModifierType *mods) { GdkModifierType raw_mods; gdk_display_get_pointer (gdk_display_get_default (), NULL, x, y, &raw_mods); *mods = raw_mods & GDK_MODIFIER_MASK; }
static VALUE rg_pointer(VALUE self) { GdkScreen *screen; int x,y; GdkModifierType mask; gdk_display_get_pointer(_SELF(self), &screen, &x, &y, &mask); return rb_ary_new3(4, GOBJ2RVAL(screen), INT2NUM(x), INT2NUM(y), INT2NUM(mask)); }
static void move(RSLoupe *loupe) { const gint distance_to_window = 50; const gint distance_to_border = 20; /* Get cursor position */ gint cursor_x=0, cursor_y=0; gdk_display_get_pointer(gdk_display_get_default(), &loupe->display_screen, &cursor_x, &cursor_y, NULL); /* Get window size */ gint window_width, window_height; gtk_window_get_size(GTK_WINDOW(loupe), &window_width, &window_height); /* Get screen size */ GdkScreen *screen = loupe->display_screen; const gint screen_width = gdk_screen_get_width(screen); const gint screen_height = gdk_screen_get_height(screen); if (loupe->left) { if ((cursor_x - window_width - distance_to_window) < distance_to_border) loupe->left = !loupe->left; } else { if ((cursor_x + window_width + distance_to_window) > (screen_width - distance_to_border)) loupe->left = !loupe->left; } if (loupe->atop) { if ((cursor_y - window_height - distance_to_window) < distance_to_border) loupe->atop = !loupe->atop; } else { if ((cursor_y + window_height + distance_to_window) > (screen_height - distance_to_border)) loupe->atop = !loupe->atop; } gint place_x, place_y; if (loupe->left) place_x = cursor_x - window_width - distance_to_window; else place_x = cursor_x + distance_to_window; if (loupe->atop) place_y = cursor_y - window_height - distance_to_window; else place_y = cursor_y + distance_to_window; gtk_window_move(GTK_WINDOW(loupe), place_x, place_y); }
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 GdkScreen * mt_main_current_screen (MTClosure *mt) { GdkScreen *screen; if (mt->n_screens > 1) gdk_display_get_pointer (gdk_display_get_default (), &screen, NULL, NULL, NULL); else screen = gdk_screen_get_default (); return screen; }
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; }
static gboolean mt_main_analyze_gesture (MTClosure *mt) { gint x, y, gd, i, dx, dy; if (mt_service_get_clicktype (mt->service) == DWELL_CLICK_TYPE_DRAG) return TRUE; gdk_display_get_pointer (gdk_display_get_default (), NULL, &x, &y, NULL); if (below_threshold (mt, x, y)) return FALSE; dx = ABS (x - mt->pointer_x); dy = ABS (y - mt->pointer_y); /* find direction */ if (x < mt->pointer_x) if (y < mt->pointer_y) if (dx < dy) gd = DIRECTION_UP; else gd = DIRECTION_LEFT; else if (dx < dy) gd = DIRECTION_DOWN; else gd = DIRECTION_LEFT; else if (y < mt->pointer_y) if (dx < dy) gd = DIRECTION_UP; else gd = DIRECTION_RIGHT; else if (dx < dy) gd = DIRECTION_DOWN; else gd = DIRECTION_RIGHT; /* get click type for direction */ for (i = 0; i < N_CLICK_TYPES; i++) { if (mt->dwell_dirs[i] == gd) { mt_service_set_clicktype (mt->service, i, NULL); return TRUE; } } return FALSE; }
static gboolean mouse_watch(panel *p) { gint x, y; ENTER; gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, &y, NULL); /* Reduce sensitivity area p->ah_far = ((x < p->cx - GAP) || (x > p->cx + p->cw + GAP) || (y < p->cy - GAP) || (y > p->cy + p->ch + GAP)); */ gint cx, cy, cw, ch; cx = p->cx; cy = p->cy; cw = p->aw; ch = p->ah; /* reduce area which will raise panel so it does not interfere with apps */ if (p->ah_state == ah_state_hidden) { switch (p->edge) { case EDGE_LEFT: cw = GAP; break; case EDGE_RIGHT: cx = cx + cw - GAP; cw = GAP; break; case EDGE_TOP: ch = GAP; break; case EDGE_BOTTOM: cy = cy + ch - GAP; ch = GAP; break; } } p->ah_far = ((x < cx) || (x > cx + cw) || (y < cy) || (y > cy + ch)); p->ah_state(p); RET(TRUE); }
/* this is used to grab the keyboard and mouse to the root */ gboolean gs_grab_grab_root (GSGrab *grab, gboolean hide_cursor) { GdkDisplay *display; GdkWindow *root; GdkScreen *screen; gboolean res; gs_debug ("Grabbing the root window"); display = gdk_display_get_default (); gdk_display_get_pointer (display, &screen, NULL, NULL, NULL); root = gdk_screen_get_root_window (screen); res = gs_grab_grab_window (grab, root, screen, hide_cursor); return res; }
void mt_ctw_update_visibility (MTClosure *mt) { GtkWidget *ctw; GdkScreen *screen; ctw = mt_ctw_get_window (mt); if (mt->dwell_enabled && mt->dwell_show_ctw) { if (mt->n_screens > 1) { gdk_display_get_pointer (gdk_display_get_default (), &screen, NULL, NULL, NULL); gtk_window_set_screen (GTK_WINDOW (ctw), screen); } gtk_widget_show (ctw); } else { gtk_widget_hide (ctw); } }
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; }
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); }
int main (int argc, char **argv) { gtk_init (&argc, &argv); read_config (); // Read options from command-line arguments. GError *error = NULL; GOptionContext *context; context = g_option_context_new (" - show X11 windows as colour mosaic"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s\n", error->message); exit (1); } g_option_context_free (context); if(options.format && !options.read_stdin) { g_printerr("You must provide option --read-stdin!"); exit(1); } #ifdef X11 atoms_init (); #endif if (already_opened ()) { g_printerr ("Another instance of xwinmosaic is opened.\n"); exit (1); } if (options.read_stdin) { if(!options.format) { options.show_icons = FALSE; options.show_desktop = FALSE; } read_stdin (); } else { #ifdef X11 // Checks whether WM supports EWMH specifications. if (!wm_supports_ewmh ()) { GtkWidget *dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error: your WM does not support EWMH specifications."); gtk_dialog_run (GTK_DIALOG (dialog)); g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_main_quit), NULL); return 1; } active_window = (Window *) property (gdk_x11_get_default_root_xwindow (), a_NET_ACTIVE_WINDOW, XA_WINDOW, NULL); #endif } if (options.color_file) read_colors (); #ifdef WIN32 if (options.persistent) { #ifdef DEBUG g_printerr ("Installing Alt-Tab hook"); #endif install_alt_tab_hook(); } #endif window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "XWinMosaic"); GdkRectangle rect = current_monitor_size (); width = rect.width; height = rect.height; if (options.at_pointer) { gdk_display_get_pointer (gdk_display_get_default (), NULL, &options.center_x, &options.center_y, NULL); gint monitors = gdk_screen_get_n_monitors (gdk_screen_get_default ()); if (monitors > 1) { guint xm = 0, ym = 0; gint current_monitor = gdk_screen_get_monitor_at_point (gdk_screen_get_default (), options.center_x, options.center_y); for (int i = 0; i < current_monitor; i++) { GdkRectangle mon_rect; gdk_screen_get_monitor_geometry (gdk_screen_get_default (), i, &mon_rect); xm += mon_rect.width; ym += mon_rect.height; } if (xm && ym) { options.center_x %= xm; options.center_y %= ym; } } if (options.center_x < options.box_width/2) options.center_x = options.box_width/2 + 1; else if (options.center_x > width - options.box_width/2) options.center_x = width - options.box_width/2 - 1; if (options.center_y < options.box_height/2) options.center_y = options.box_height/2 + 1; else if (options.center_y > height - options.box_height/2) options.center_y = height - options.box_height/2 - 1; } else { options.center_x = width/2; options.center_y = height/2; } gtk_window_set_default_size (GTK_WINDOW (window), width, height); gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER); gtk_window_set_decorated (GTK_WINDOW (window), 0); gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), 1); gtk_window_set_skip_pager_hint (GTK_WINDOW (window), 1); /**/ gtk_widget_add_events (GTK_WIDGET (window), GDK_FOCUS_CHANGE); g_signal_connect (G_OBJECT (window), "focus-out-event", G_CALLBACK (on_focus_change), NULL); /**/ layout = gtk_layout_new (NULL, NULL); gtk_container_add (GTK_CONTAINER (window), layout); if (options.screenshot) { gtk_window_fullscreen (GTK_WINDOW (window)); GdkPixbuf *screenshot; GdkPixmap *background = NULL; GtkStyle *style = NULL; screenshot = get_screenshot (); gdk_pixbuf_render_pixmap_and_mask (screenshot, &background, NULL, 0); style = gtk_style_new (); style->bg_pixmap [0] = background; gtk_widget_set_style (window, style); gtk_widget_set_style (layout, style); } search = mosaic_search_box_new (); mosaic_box_set_font (MOSAIC_BOX (search), options.font); gtk_widget_set_can_focus (search, FALSE); GtkRequisition s_req; gtk_widget_size_request (search, &s_req); gtk_layout_put (GTK_LAYOUT (layout), search, (width - s_req.width)/2, height - s_req.height - options.box_height); g_signal_connect (G_OBJECT (search), "changed", G_CALLBACK (refilter), NULL); g_signal_connect (G_OBJECT (window), "key-press-event", G_CALLBACK (on_key_press), NULL); g_signal_connect_swapped(G_OBJECT (window), "destroy", G_CALLBACK(gtk_main_quit), NULL); if (!options.screenshot) { window_shape_bitmap = (GdkDrawable *) gdk_pixmap_new (NULL, width, height, 1); draw_mask (window_shape_bitmap, 0); gtk_widget_shape_combine_mask (window, window_shape_bitmap, 0, 0); } gtk_widget_show_all (window); gtk_widget_hide (search); gtk_window_present (GTK_WINDOW (window)); gtk_window_set_keep_above (GTK_WINDOW (window), TRUE); if (options.persistent) gtk_widget_hide (window); GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window)); #ifdef X11 myown_window = GDK_WINDOW_XID (gdk_window); if (!options.read_stdin) { // Get PropertyNotify events from root window. XSelectInput (gdk_x11_get_default_xdisplay (), gdk_x11_get_default_root_xwindow (), PropertyChangeMask); gdk_window_add_filter (NULL, (GdkFilterFunc) event_filter, NULL); } #endif #ifdef WIN32 myown_window = GDK_WINDOW_HWND (gdk_window); #endif update_box_list (); draw_mosaic (GTK_LAYOUT (layout), boxes, wsize, 0, options.box_width, options.box_height); #ifdef X11 // Window will be shown on all desktops (and so hidden in windows list) unsigned int desk = 0xFFFFFFFF; // -1 XChangeProperty(gdk_x11_get_default_xdisplay (), myown_window, a_NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&desk, 1); #endif gtk_main (); #ifdef X11 if (!options.read_stdin) XFree (wins); #endif return 0; }
void Sys_GetCursorPos (GtkWindow* window, int *x, int *y) { gdk_display_get_pointer(gdk_display_get_default(), 0, x, y, 0); }
bool _HYSequencePane::_ProcessOSEvent (Ptr vEvent) { static bool amScrolling = false, vertical; static long localPt_x, localPt_y, originalStart, originalSpan, lastClick, firstClick; if (_HYPlatformComponent::_ProcessOSEvent (vEvent)) return true; _HY_GTK_UI_Message *theMessage = (_HY_GTK_UI_Message*)vEvent; if (active) { gdouble xc, yc; if (gdk_event_get_coords (theMessage->theEvent,&xc,&yc)) { switch (theMessage->theEvent->type) { case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: { GdkEventButton * bevent = (GdkEventButton*)theMessage->theEvent; long globalPt_x = xc, globalPt_y = yc; localPt_x = globalPt_x-rel.left-parentWindow->allocation.x; localPt_y = globalPt_y-rel.top-parentWindow->allocation.y; vertical = (localPt_x<headerWidth)&&(localPt_y>=(GetSlotHeight()+1)); if (((GdkEventButton*)bevent)->button == 1) { if (vertical) ProcessVSelectionChange (localPt_x,localPt_y,bevent->state & GDK_SHIFT_MASK,bevent->state & GDK_CONTROL_MASK, false, bevent->type == GDK_2BUTTON_PRESS); else ProcessSelectionChange (localPt_x,localPt_y,bevent->state & GDK_SHIFT_MASK,bevent->state & GDK_CONTROL_MASK); } else { if ((((GdkEventButton*)bevent)->button == 2 || ((GdkEventButton*)bevent)->button == 3 )&& (vertical&&vselection.lLength || !vertical &&selection.lLength)) { ProcessContextualPopUp (globalPt_x, globalPt_y); return true; } } } break; case GDK_BUTTON_RELEASE: case GDK_LEAVE_NOTIFY: { if (amScrolling) { if (messageRecipient) ((_HYTWindow*)messageRecipient)->trackMouseComponent = (Ptr)nil; /*gdk_pointer_ungrab (((GdkEventButton*)theMessage->theEvent)->time);*/ if (vertical) { _HYRect invalRectH = {parentWindow->allocation.x+rel.left, parentWindow->allocation.y+rel.top+(GetSlotHeight()+1)+1,rel.left+headerWidth,rel.bottom-HY_SCROLLER_WIDTH}; GdkRectangle irect = HYRect2GDKRect(invalRectH); irect.x+=parentWindow->allocation.x; irect.y+=parentWindow->allocation.y; gdk_window_invalidate_rect (parentWindow->window, &irect, false); if ( localPt_x<headerWidth && localPt_x>0 && lastClick>-2) MoveSpecies (firstClick+originalStart,lastClick+startRow); } amScrolling = false; } break; } case GDK_MOTION_NOTIFY: { GdkEventMotion * motEvent = (GdkEventMotion*)theMessage->theEvent; if (motEvent->state & GDK_BUTTON1_MASK) { if (amScrolling) { gint mousePt_x = motEvent->x - rel.left - parentWindow->allocation.x, mousePt_y = motEvent->y - rel.top - parentWindow->allocation.y; if (vertical) // vertical scrolling { long wHeight = rel.bottom-rel.top-HY_SCROLLER_WIDTH, slotHeight = GetSlotHeight(); if ( mousePt_y < GetSlotHeight()+1 || localPt_y != mousePt_y || mousePt_y>wHeight ) { localPt_x = mousePt_x; localPt_y = mousePt_y; if (mousePt_y>wHeight) { // scroll down if ((endRow<=speciesIndex.lLength)&&(vselection.lData[0]!=speciesIndex.lLength-1)) { if (endRow-startRow<originalSpan) break; startRow++; endRow++; _SetVScrollerPos(((double)MAX_CONTROL_VALUE*startRow)/ (speciesIndex.lLength-endRow+startRow+1)); BuildPane(); forceUpdateForScrolling = true; _MarkForUpdate(); forceUpdateForScrolling = false; lastClick = -2; } break; } else { mousePt_y-=(GetSlotHeight()+1); if (mousePt_y<=slotHeight) { if (mousePt_y>=0) { if (mousePt_y<slotHeight/2) mousePt_y = -1; else mousePt_y = 0; } else { // scroll up if (startRow>0) { startRow--; endRow--; _SetVScrollerPos(((double)MAX_CONTROL_VALUE*startRow)/(speciesIndex.lLength-endRow+startRow+1)); BuildPane(); forceUpdateForScrolling = true; _MarkForUpdate(); forceUpdateForScrolling = false; lastClick = -2; } break; } } else mousePt_y=(mousePt_y-(GetSlotHeight()+1))/slotHeight; } if ( mousePt_y<-1 || mousePt_y>= endRow-startRow ) break; if (mousePt_y!=lastClick) { GdkDrawable * tempDr = GDK_DRAWABLE(parentWindow->window); GdkGC * tempGC = gdk_gc_new (tempDr); GdkColor black = HYColorToGDKColor((_HYColor){0,0,0}); gdk_gc_set_foreground (theContext, &black); gdk_gc_set_function (tempGC, GDK_INVERT); gdk_gc_set_line_attributes (tempGC, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER); if (lastClick>=-1) { lastClick = (GetSlotHeight()+1)+slotHeight*(lastClick+1)+rel.top+1; gdk_draw_line (tempDr,tempGC,parentWindow->allocation.x+rel.left+1,parentWindow->allocation.y+lastClick, parentWindow->allocation.x+rel.left+headerWidth-1,parentWindow->allocation.y+lastClick); } lastClick = mousePt_y; if (lastClick+startRow != firstClick+originalStart) { mousePt_y = (GetSlotHeight()+1)+slotHeight*(lastClick+1)+rel.top+1; gdk_draw_line (tempDr,tempGC,parentWindow->allocation.x+rel.left+1,parentWindow->allocation.y+mousePt_y, parentWindow->allocation.x+rel.left+headerWidth-1,parentWindow->allocation.y+mousePt_y); } g_object_unref (tempGC); } } return true; } else // horizontal scrolling { long rightWindowBound = _HYCanvas::GetMaxW()-HY_SCROLLER_WIDTH; guint32 serverTime = gdk_x11_get_server_time (parentWindow->window); if ( mousePt_x<headerWidth && startColumn>0 || localPt_x!=mousePt_x || mousePt_x> rightWindowBound) { forceUpdateForScrolling = true; if (mousePt_x<headerWidth && startColumn>0) { gint wx, wy; gdk_window_get_origin (parentWindow->window,&wx,&wy); wx += parentWindow->allocation.x+rel.left; wy += parentWindow->allocation.y+rel.top; do { guint32 serverTime2 = gdk_x11_get_server_time (parentWindow->window); if (serverTime2-serverTime < 100) ProcessSelectionChange (mousePt_x,mousePt_y,true,true,true); GdkModifierType keyDown; gdk_display_get_pointer (gdk_display_get_default(),NULL,&mousePt_x,&mousePt_y,&keyDown); mousePt_x -= wx; mousePt_y -= wy; serverTime = serverTime2; if ((keyDown & GDK_BUTTON1_MASK)==0) break; gtk_main_iteration_do(true); } while (mousePt_x<headerWidth && startColumn>0); } else { if (mousePt_x> rightWindowBound) { gint wx, wy; gdk_window_get_origin (parentWindow->window,&wx,&wy); wx += parentWindow->allocation.x; wy += parentWindow->allocation.y; do { guint32 serverTime2 = gdk_x11_get_server_time (parentWindow->window); if (serverTime2-serverTime < 100) ProcessSelectionChange (mousePt_x+HY_SCROLLER_WIDTH,mousePt_y,true,true,true); GdkModifierType keyDown; gdk_display_get_pointer (gdk_display_get_default(),NULL,&mousePt_x,&mousePt_y,&keyDown); mousePt_x -= wx; mousePt_y -= wy; serverTime = serverTime2; if ((keyDown & GDK_BUTTON1_MASK)==0) break; gtk_main_iteration_do(true); } while (mousePt_x> rightWindowBound && endColumn < columnStrings.lLength); } else if (serverTime-gdk_event_get_time(theMessage->theEvent) < 100) ProcessSelectionChange (mousePt_x,mousePt_y,true,true,true); } forceUpdateForScrolling = false; localPt_x = mousePt_x; localPt_y = mousePt_y; } return true; } } else { /*gdk_pointer_grab (parentWindow->window,false, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, (((GdkEventMotion*)theMessage->theEvent))->time);*/ if (messageRecipient) ((_HYTWindow*)messageRecipient)->trackMouseComponent = (Ptr)((_HYComponent*)this); amScrolling = true; originalStart = startRow, originalSpan = endRow-startRow; lastClick = -2; firstClick = (localPt_y-(GetSlotHeight()+1))/GetSlotHeight(); return true; } } break; } } } } return false; }
static void mouse_handler(GtkWidget *w, GdkEvent *event, gpointer data) { video_canvas_t *canvas = (video_canvas_t *)data; if (event->type == GDK_BUTTON_PRESS) { GdkEventButton *bevent = (GdkEventButton*)event; if (_mouse_enabled || lightpen_enabled) { mouse_button(bevent->button-1, TRUE); gtk_lightpen_setbutton(bevent->button, TRUE); } else { if (bevent->button == 1) { ui_menu_update_all_GTK(); gtk_menu_popup(GTK_MENU(left_menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); } else if (bevent->button == 3) { ui_menu_update_all_GTK(); gtk_menu_popup(GTK_MENU(right_menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); } } } else if (event->type == GDK_BUTTON_RELEASE && (_mouse_enabled || lightpen_enabled)) { GdkEventButton *bevent = (GdkEventButton*)event; mouse_button(bevent->button-1, FALSE); gtk_lightpen_setbutton(bevent->button, FALSE); } else if (event->type == GDK_MOTION_NOTIFY) { GdkEventMotion *mevent = (GdkEventMotion*)event; if (_mouse_enabled) { /* handle pointer motion events for mouse emulation */ gint x=0, y=0, w=0, h=0, warp=0; gint xoff=0, yoff=0; gint ptrx, ptry; GdkDisplay *display = NULL; GdkScreen *screen = NULL; /* get default display and screen */ display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); /* get cursor position */ gdk_display_get_pointer (display, NULL, &x, &y, NULL); ptrx = (int)mevent->x; ptry = (int)mevent->y; xoff = x - ptrx; yoff = y - ptry; /* w = canvas->draw_buffer->canvas_physical_width; */ w = gtk_widget_get_allocated_width(canvas->emuwindow); h = canvas->draw_buffer->canvas_physical_height; /* DBG(("ptrx:%d ptry:%d x:%d y:%d w:%d h:%d", ptrx, ptry, x, y, w, h)); */ if (mouse_warpx == 1) { /* from left to right */ if ((ptrx > mouse_lasteventx) && (ptrx >= (w - (MOUSE_WRAP_MARGIN * 2))) && (ptrx <= (w - MOUSE_WRAP_MARGIN))) { mouse_warpx = 0; mouse_lasteventx = ptrx; } } else if (mouse_warpx == 2) { /* from right to left */ if ((ptrx < mouse_lasteventx) && (ptrx <= (MOUSE_WRAP_MARGIN * 2)) && (ptrx >= MOUSE_WRAP_MARGIN)) { mouse_warpx = 0; mouse_lasteventx = ptrx; } } if (mouse_warpy == 1) { /* from top to bottom */ if ((ptry > mouse_lasteventy) && (ptry >= (h - (MOUSE_WRAP_MARGIN * 2))) && (ptry <= (h - MOUSE_WRAP_MARGIN))) { mouse_warpy = 0; mouse_lasteventy = ptry; } } else if (mouse_warpy == 2) { /* from bottom to top */ if ((ptry < mouse_lasteventy) && (ptry <= (MOUSE_WRAP_MARGIN * 2)) && (ptry >= MOUSE_WRAP_MARGIN)) { mouse_warpy = 0; mouse_lasteventy = ptry; } } if (mouse_warped || mouse_warpx || mouse_warpy) { /* ignore this event, its the result of us having moved the pointer */ /* DBG(("warped!:%d/%d/%d ptrx:%d ptry:%d lastx:%d lasty:%d", mouse_warped, mouse_warpx, mouse_warpy, ptrx, ptry, mouse_lasteventx, mouse_lasteventy)); */ if (mouse_warped) { --mouse_warped; } } else { if (ptrx < MOUSE_WRAP_MARGIN) { /* from left to right */ mouse_lasteventx = ptrx; ptrx = w - (MOUSE_WRAP_MARGIN + 10); mouse_warpx = 1; warp = 1; } else if (ptrx > (w - MOUSE_WRAP_MARGIN)) { /* from right to left */ mouse_lasteventx = ptrx; ptrx = (MOUSE_WRAP_MARGIN + 10); mouse_warpx = 2; warp = 1; } if (ptry < (MOUSE_WRAP_MARGIN)) { /* from top to bottom */ mouse_lasteventy = ptry; ptry = (h - (MOUSE_WRAP_MARGIN + 10)); mouse_warpy = 1; warp = 1; } else if (ptry > (h - MOUSE_WRAP_MARGIN)) { /* from bottom to top */ mouse_lasteventy = ptry; ptry = (MOUSE_WRAP_MARGIN + 10); mouse_warpy = 2; warp = 1; } /* DBG(("warp:%d ptrx:%d ptry:%d x:%d y:%d w:%d h:%d", warp, ptrx, ptry, x, y, w, h)); */ if (warp) { /* set new cusor position */ ++mouse_warped; /* DBG(("warp to: x:%d y:%d", ptrx, ptry)); */ gdk_display_warp_pointer (display, screen, ptrx + xoff, ptry + yoff); } else { mouse_dx = (ptrx - mouse_lasteventx) / (canvas->videoconfig->doublesizex + 1); mouse_dy = (ptry - mouse_lasteventy) / (canvas->videoconfig->doublesizey + 1); DBG(("mouse move dx:%8d dy:%8d", mouse_dx, mouse_dy)); mouse_move((float)mouse_dx, (float)mouse_dy); mouse_lasteventx = ptrx; mouse_lasteventy = ptry; } } } #ifdef HAVE_FULLSCREEN fullscreen_mouse_moved(canvas, (int)mevent->x, (int)mevent->y, 0); #endif } }
NS_IMETHODIMP sbNativeWindowManager::BeginResizeDrag(nsISupports *aWindow, nsIDOMMouseEvent* aEvent, PRInt32 aDirection) { nsresult rv; PRInt32 screenX; PRInt32 screenY; PRUint16 button; PRUint32 server_time; GdkWindow* window = NULL; GdkWindowEdge window_edge; NS_ENSURE_ARG_POINTER(aWindow); NS_ENSURE_ARG_POINTER(aEvent); /* find the window that was passed in */ rv = GetToplevelGdkWindow(aWindow, &window); NS_ENSURE_SUCCESS(rv, rv); /* get the currently pressed mouse button from the event */ rv = aEvent->GetButton(&button); NS_ENSURE_SUCCESS(rv, rv); /* mozilla and gtk disagree about button numbering... */ button++; /* to work around an old, buggy metacity we need to move ourselves */ /* where are we? */ gdk_window_get_position(window, &screenX, &screenY); /* let's move to there */ gdk_window_move(window, screenX, screenY); #ifdef MOUSE_POSITION_FROM_EVENT /* pull the mouse position out of the mozilla event */ rv = aEvent->GetScreenX(&screenX); NS_ENSURE_SUCCESS(rv, rv); rv = aEvent->GetScreenY(&screenY); NS_ENSURE_SUCCESS(rv, rv); #else { /* ask X where the mouse is */ GdkDisplay* display = NULL; GdkScreen* screen = NULL; GdkModifierType mask; /* get the current (default) display */ display = gdk_display_get_default(); if (display == NULL) { return NS_ERROR_FAILURE; } /* get the current pointer position */ gdk_display_get_pointer(display, &screen, &screenX, &screenY, &mask); } #endif /* convert interface directions to GDK_WINDOW_EDGE* */ switch(aDirection) { case sbINativeWindowManager::DIRECTION_NORTH_WEST: window_edge = GDK_WINDOW_EDGE_NORTH_WEST; break; case sbINativeWindowManager::DIRECTION_NORTH: window_edge = GDK_WINDOW_EDGE_NORTH; break; case sbINativeWindowManager::DIRECTION_NORTH_EAST: window_edge = GDK_WINDOW_EDGE_NORTH_EAST; break; case sbINativeWindowManager::DIRECTION_WEST: window_edge = GDK_WINDOW_EDGE_WEST; break; case sbINativeWindowManager::DIRECTION_EAST: window_edge = GDK_WINDOW_EDGE_EAST; break; case sbINativeWindowManager::DIRECTION_SOUTH_WEST: window_edge = GDK_WINDOW_EDGE_SOUTH_WEST; break; case sbINativeWindowManager::DIRECTION_SOUTH: window_edge = GDK_WINDOW_EDGE_SOUTH; break; case sbINativeWindowManager::DIRECTION_SOUTH_EAST: window_edge = GDK_WINDOW_EDGE_SOUTH_EAST; break; default: return NS_ERROR_FAILURE; } /* if I were an event, when would I happen? */ server_time = gdk_x11_get_server_time(window); /* tell the window manager to start the resize */ gdk_window_begin_resize_drag(window, window_edge, button, screenX, screenY, server_time); return NS_OK; }