static void get_grab_cb (GtkWidget * self, gpointer data) { MenuStart *menu = (MenuStart *) data; GdkWindow *window = g_object_get_data (G_OBJECT (menu), "gtk-menu-transfer-window"); popup_grab_on_window (window, GDK_CURRENT_TIME); }
static void popup_container_show (GtkWidget *widget) { PopupContainer *container = (PopupContainer *) widget; gint x, y; GTK_WIDGET_CLASS (parent_class)->show (widget); if (container->priv->position_func) container->priv->position_func (container, &x, &y); else default_position_func (container, &x, &y); gtk_window_move (GTK_WINDOW (widget), x + 1, y + 1); gtk_window_move (GTK_WINDOW (widget), x, y); gtk_grab_add (widget); GdkScreen *screen; gint swidth, sheight; gint root_x, root_y; gint wwidth, wheight; gboolean do_move = FALSE; screen = gtk_window_get_screen (GTK_WINDOW (widget)); if (screen) { swidth = gdk_screen_get_width (screen); sheight = gdk_screen_get_height (screen); } else { swidth = gdk_screen_width (); sheight = gdk_screen_height (); } gtk_window_get_position (GTK_WINDOW (widget), &root_x, &root_y); gtk_window_get_size (GTK_WINDOW (widget), &wwidth, &wheight); if (root_x + wwidth > swidth) { do_move = TRUE; root_x = swidth - wwidth; } else if (root_x < 0) { do_move = TRUE; root_x = 0; } if (root_y + wheight > sheight) { do_move = TRUE; root_y = sheight - wheight; } else if (root_y < 0) { do_move = TRUE; root_y = 0; } if (do_move) gtk_window_move (GTK_WINDOW (widget), root_x, root_y); popup_grab_on_window (widget, gtk_get_current_event_time ()); }
static void on_pressed(GtkButton* button, gpointer user_data) { AbiTable* table = static_cast<AbiTable*>(user_data); int left, top; GdkColor selected_color; /* Temporarily grab pointer and keyboard on a window we know exists; we * do this so that the grab (with owner events == TRUE) affects * events generated when the window is mapped, such as enter * notify events on subwidgets. If the grab fails, bail out. */ if (!popup_grab_on_window (GTK_WIDGET(button)->window, gtk_get_current_event_time ())) return; gdk_window_get_origin (GTK_WIDGET(table)->window, &left, &top); gtk_window_move(table->window, left + GTK_WIDGET(table)->allocation.x, top + GTK_WIDGET(table)->allocation.y + GTK_WIDGET(table)->allocation.height); abi_table_resize(table); gtk_widget_show(GTK_WIDGET(table->window)); gtk_widget_grab_focus(GTK_WIDGET(table->window)); /* Now transfer our grabs to the popup window; this * should always succeed. */ popup_grab_on_window (GTK_WIDGET(table->area)->window, gtk_get_current_event_time ()); selected_color = (GTK_WIDGET (button))->style->base[GTK_STATE_SELECTED]; /* leak */ table->selected_gc = gdk_gc_new(GTK_WIDGET(button)->window); gdk_gc_set_rgb_fg_color(table->selected_gc, &selected_color); }
void menu_start_show (MenuStart * ms, int xpos, int ypos, MenuStartPosition pos) { GdkWindow *transfer_window; transfer_window = menu_grab_transfer_window_get (ms); if (!popup_grab_on_window (transfer_window, GDK_CURRENT_TIME)) return; gtk_widget_set_size_request (GTK_WIDGET (ms), ms->width, ms->height); if (ms->show_header) { gtk_widget_show (ms->header); } else { gtk_widget_hide (ms->header); } gtk_widget_hide (ms->small_header); if (ms->show_footer) { gtk_widget_show_all (ms->footbox); gtk_widget_hide (ms->small_footer); } else { gtk_widget_hide (ms->footbox); gtk_widget_show_all (ms->small_footer); } gtk_widget_hide (ms->fsbrowser); gtk_widget_hide (ms->fstab); gtk_widget_show (ms->menu_ebox); update_ms_header (ms, _("Menu"), "gtk-index"); show_menu_widget (ms->menu); if (pos == MENU_START_BOTTOM) gtk_window_move (GTK_WINDOW (ms), xpos, ypos); else { gtk_window_move (GTK_WINDOW (ms), xpos, ypos); } gtk_widget_show (GTK_WIDGET (ms)); gtk_grab_add (GTK_WIDGET (ms)); }
void budgie_popover_present(BudgiePopover *self, GtkWidget *parent, GdkEventButton *event) { GtkWidget *real_parent; GdkWindow *parent_window; gint x, y, tx, ty, rx, margin; GdkScreen *screen; GtkAllocation alloc, our_alloc; GdkDeviceManager *manager; gint32 time; if (event) { x = event->x; y = event->y; } if (gtk_widget_get_visible(GTK_WIDGET(self))) { budgie_popover_hide(self); return; } if (!gtk_widget_get_realized(GTK_WIDGET(self))) gtk_widget_realize(GTK_WIDGET(self)); /* Get position of parent widget on screen */ real_parent = gtk_widget_get_toplevel(parent); parent_window = gtk_widget_get_window(real_parent); gdk_window_get_position(parent_window, &x, &y); gtk_widget_translate_coordinates(parent, real_parent, x, y, &tx, &ty); gtk_widget_get_allocation(parent, &alloc); gtk_widget_get_allocation(GTK_WIDGET(self), &our_alloc); screen = gtk_widget_get_screen(GTK_WIDGET(self)); /* Ensure we're in a sensible position (under/over) */ if (ty + our_alloc.height + 11 < gdk_screen_get_height(screen)) { self->top = TRUE; ty = y+alloc.y+alloc.height; } else { ty = (y+alloc.y)-our_alloc.height; self->top = FALSE; } /* Ensure widg_x is within bounds */ if (event) { /* Point tip to mouse x,y */ rx = event->x; } else { /* Center the tip when there is no event */ rx = alloc.x + (alloc.width/2); } /* ensure margin is accounted for */ g_object_get(parent, "margin", &margin, NULL); tx -= margin; rx -= margin; if (rx >= our_alloc.width) rx = our_alloc.width - 18; if (rx <= 18) rx = 18; self->widg_x = rx; gtk_window_move(GTK_WINDOW(self), tx-11, ty); gtk_widget_show_all(GTK_WIDGET(self)); if (event) { self->pointer = event->device; time = event->time; } else { manager = gdk_display_get_device_manager(gdk_screen_get_display(screen)); self->pointer = gdk_device_manager_get_client_pointer(manager); time = GDK_CURRENT_TIME; } self->parent_widget = real_parent; self->con_id = g_signal_connect(real_parent, "button-press-event", G_CALLBACK(button_press), self); self->con_id = 0; /* TODO: Handle keyboard grab too */ popup_grab_on_window(gtk_widget_get_window(GTK_WIDGET(real_parent)), NULL, self->pointer, time); }
static void gnc_date_edit_popup (GNCDateEdit *gde) { GtkWidget *toplevel; struct tm mtm; gboolean date_was_valid; GdkDevice *device, *keyboard, *pointer; g_return_if_fail (GNC_IS_DATE_EDIT (gde)); ENTER("gde %p", gde); device = gtk_get_current_event_device (); /* This code is pretty much just copied from gtk_date_edit_get_date */ date_was_valid = qof_scan_date (gtk_entry_get_text (GTK_ENTRY (gde->date_entry)), &mtm.tm_mday, &mtm.tm_mon, &mtm.tm_year); if (!date_was_valid) { /* No valid date. Hacky workaround: Instead of crashing we randomly choose today's date. */ gnc_tm_get_today_start(&mtm); } mtm.tm_mon--; /* Hope the user does not actually mean years early in the A.D. days... * This date widget will obviously not work for a history program :-) */ if (mtm.tm_year >= 1900) mtm.tm_year -= 1900; gnc_tm_set_day_start(&mtm); /* Set the calendar. */ gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), 1); gtk_calendar_select_month (GTK_CALENDAR (gde->calendar), mtm.tm_mon, 1900 + mtm.tm_year); gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), mtm.tm_mday); /* Make sure we'll get notified of clicks outside the popup * window so we can properly pop down if that happens. */ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (gde)); if (GTK_IS_WINDOW (toplevel)) { gtk_window_group_add_window ( gtk_window_get_group (GTK_WINDOW (toplevel)), GTK_WINDOW (gde->cal_popup)); gtk_window_set_transient_for (GTK_WINDOW (gde->cal_popup), GTK_WINDOW (toplevel)); } position_popup (gde); gtk_widget_show (gde->cal_popup); gtk_widget_grab_focus (gde->cal_popup); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gde->date_button), TRUE); if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) { keyboard = device; pointer = gdk_device_get_associated_device (device); } else { pointer = device; keyboard = gdk_device_get_associated_device (device); } if (!gtk_widget_has_focus (gde->calendar)) gtk_widget_grab_focus (gde->calendar); if (!popup_grab_on_window (gtk_widget_get_window ((GTK_WIDGET(gde->cal_popup))), keyboard, pointer, GDK_CURRENT_TIME)) { gtk_widget_hide (gde->cal_popup); LEAVE("Failed to grab window"); return; } gtk_grab_add (gde->cal_popup); LEAVE(" "); }