/* private methods */ static gboolean expose_event (GtkWidget *widget, cairo_t *cr1, gpointer dara) { cairo_t *cr; gint w, h; TboDrawing *self = TBO_DRAWING (widget); cr = gdk_cairo_create(gtk_layout_get_bin_window (GTK_LAYOUT (widget))); w = gdk_window_get_width (gtk_layout_get_bin_window (GTK_LAYOUT (widget))); h = gdk_window_get_height (gtk_layout_get_bin_window (GTK_LAYOUT (widget))); cairo_set_source_rgb (cr, 0, 0, 0); cairo_rectangle (cr, 0, 0, w, h); cairo_fill (cr); tbo_drawing_draw (TBO_DRAWING (widget), cr); tbo_tooltip_draw (cr); // Update drawing helpers if (self->tool) self->tool->drawing (self->tool, cr); cairo_destroy(cr); return FALSE; }
static gboolean motion_cb (GocCanvas *canvas, GdkEventMotion *event, G_GNUC_UNUSED gpointer data) { double x, y; GocItem *item; gboolean result = FALSE; if (event->window != gtk_layout_get_bin_window (&canvas->base)) return TRUE; x = (canvas->direction == GOC_DIRECTION_RTL)? canvas->scroll_x1 + (canvas->width - event->x) / canvas->pixels_per_unit: canvas->scroll_x1 + event->x / canvas->pixels_per_unit; y = canvas->scroll_y1 + event->y / canvas->pixels_per_unit; if (canvas->grabbed_item != NULL) item = canvas->grabbed_item; else item = goc_canvas_get_item_at (canvas, x, y); canvas->cur_event = (GdkEvent *) event; if (canvas->last_item && item != canvas->last_item) { GOC_ITEM_GET_CLASS (canvas->last_item)->leave_notify (canvas->last_item, x, y); canvas->last_item = NULL; } if (item) { GocItemClass *klass = GOC_ITEM_GET_CLASS (item); if (item != canvas->last_item) { canvas->last_item = item; klass->enter_notify (item, x, y); } result = klass->motion (item, x, y); } canvas->cur_event = NULL; return result; }
static gboolean animate_expander (gpointer data) { GtkLayout *layout; GdkWindow *window; animate_closure_t *closure = (animate_closure_t *) data; cairo_t *cr; if (closure->finish) { e_tree_table_adapter_node_set_expanded (closure->etta, closure->node, !closure->expanded); closure->ectv->animate_timeout = 0; g_free (data); return FALSE; } layout = GTK_LAYOUT (closure->ectv->canvas); window = gtk_layout_get_bin_window (layout); cr = gdk_cairo_create (window); draw_expander ( closure->ectv, cr, closure->expanded ? GTK_EXPANDER_SEMI_COLLAPSED : GTK_EXPANDER_SEMI_EXPANDED, GTK_STATE_NORMAL, &closure->area); closure->finish = TRUE; cairo_destroy (cr); return TRUE; }
static gboolean layout_expose_handler (GtkWidget *widget, GdkEventExpose *event) { GtkLayout *layout = GTK_LAYOUT (widget); GdkWindow *bin_window = gtk_layout_get_bin_window (layout); cairo_t *cr; gint i,j; gint imin, imax, jmin, jmax; if (event->window != bin_window) return FALSE; imin = (event->area.x) / 10; imax = (event->area.x + event->area.width + 9) / 10; jmin = (event->area.y) / 10; jmax = (event->area.y + event->area.height + 9) / 10; cr = gdk_cairo_create (bin_window); for (i = imin; i < imax; i++) for (j = jmin; j < jmax; j++) if ((i + j) % 2) cairo_rectangle (cr, 10 * i, 10 * j, 1 + i % 10, 1 + j % 10); cairo_fill (cr); cairo_destroy (cr); return FALSE; }
static void athena_desktop_background_set_up_widget (AthenaDesktopBackground *self) { GdkWindow *window; gboolean in_fade = FALSE; GtkWidget *widget; widget = self->details->widget; if (!gtk_widget_get_realized (widget)) { return; } athena_desktop_background_ensure_realized (self); window = gtk_layout_get_bin_window (GTK_LAYOUT (widget)); in_fade = fade_to_surface (self, window, self->details->background_surface); if (!in_fade) { cairo_pattern_t *pattern; pattern = cairo_pattern_create_for_surface (self->details->background_surface); gdk_window_set_background_pattern (window, pattern); cairo_pattern_destroy (pattern); gnome_bg_set_surface_as_root (gtk_widget_get_screen (widget), self->details->background_surface); } }
static gboolean idle_do_action (gpointer data) { GtkLayout *layout; GdkEventButton event; ETableClickToAdd * etcta; gint finished; g_return_val_if_fail (data!= NULL, FALSE); etcta = E_TABLE_CLICK_TO_ADD ( atk_gobject_accessible_get_object ( ATK_GOBJECT_ACCESSIBLE (data))); g_return_val_if_fail (etcta, FALSE); layout = GTK_LAYOUT (GNOME_CANVAS_ITEM (etcta)->canvas); event.x = 0; event.y = 0; event.type = GDK_BUTTON_PRESS; event.window = gtk_layout_get_bin_window (layout); event.button = 1; event.send_event = TRUE; event.time = GDK_CURRENT_TIME; event.axes = NULL; g_signal_emit_by_name (etcta, "event", &event, &finished); return FALSE; }
GdkWindow *nsgtk_layout_get_bin_window(GtkLayout *layout) { #if GTK_CHECK_VERSION(2,14,0) return gtk_layout_get_bin_window(layout); #else return layout->bin_window; #endif }
bool C4Window::ReInit(C4AbstractApp* pApp) { // Check whether multisampling settings was changed. If not then we // don't need to ReInit anything. #ifdef GDK_WINDOWING_X11 int value; Display * const dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default()); glXGetFBConfigAttrib(dpy, Info, GLX_SAMPLES, &value); if(value == Config.Graphics.MultiSampling) return true; // Check whether we have a visual with the requested number of samples GLXFBConfig new_info; if(!FindFBConfig(Config.Graphics.MultiSampling, &new_info)) return false; GdkScreen * scr = gtk_widget_get_screen(GTK_WIDGET(render_widget)); XVisualInfo *vis_info = glXGetVisualFromFBConfig(dpy, new_info); assert(vis_info); GdkVisual * vis = gdk_x11_screen_lookup_visual(scr, vis_info->visualid); XFree(vis_info); // Un- and re-realizing the render_widget does not work, the window // remains hidden afterwards. So we re-create it from scratch. gtk_widget_destroy(GTK_WIDGET(render_widget)); render_widget = gtk_drawing_area_new(); #if !GTK_CHECK_VERSION(3,10,0) gtk_widget_set_double_buffered (GTK_WIDGET(render_widget), false); #endif g_object_set(G_OBJECT(render_widget), "can-focus", TRUE, NULL); gtk_widget_set_visual(GTK_WIDGET(render_widget),vis); Info = new_info; // Wait until window is mapped to get the window's XID gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(render_widget)); gtk_widget_show_now(GTK_WIDGET(render_widget)); if (GTK_IS_LAYOUT(render_widget)) { GdkWindow* bin_wnd = gtk_layout_get_bin_window(GTK_LAYOUT(render_widget)); renderwnd = GDK_WINDOW_XID(bin_wnd); } else { GdkWindow* render_wnd = gtk_widget_get_window(GTK_WIDGET(render_widget)); renderwnd = GDK_WINDOW_XID(render_wnd); } gdk_flush(); gdk_window_set_cursor(gtk_widget_get_window(GTK_WIDGET(render_widget)), gdk_cursor_new_for_display(gdk_display_get_default(), GDK_BLANK_CURSOR)); return true; #endif }
static gboolean preview_draw (GtkWidget *widget, cairo_t *cr, SoliPrintPreview *preview) { GdkWindow *bin_window; gint tile_width; gint page_num; gint n_pages; gint col; bin_window = gtk_layout_get_bin_window (preview->layout); if (!gtk_cairo_should_draw_window (cr, bin_window)) { return GDK_EVENT_STOP; } cairo_save (cr); gtk_cairo_transform_to_window (cr, widget, bin_window); get_tile_size (preview, &tile_width, NULL); n_pages = get_n_pages (preview); col = 0; page_num = get_first_page_displayed (preview); while (col < preview->n_columns && page_num < n_pages) { if (!gtk_print_operation_preview_is_selected (preview->gtk_preview, page_num)) { page_num++; continue; } draw_page (cr, col * tile_width, 0, page_num, preview); col++; page_num++; } cairo_restore (cr); return GDK_EVENT_STOP; }
static void tbo_drawing_realize (GtkWidget *widget) { GdkWindow *bin_window; if (GTK_WIDGET_CLASS (tbo_drawing_parent_class)->realize) (* GTK_WIDGET_CLASS (tbo_drawing_parent_class)->realize) (widget); bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (widget)); gdk_window_set_events (bin_window, (gdk_window_get_events (bin_window) | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK)); }
static gboolean gnc_header_draw (GtkWidget *header, cairo_t *cr) { GnucashSheet *sheet = GNC_HEADER(header)->sheet; GdkWindow *sheet_layout_win = gtk_layout_get_bin_window (GTK_LAYOUT(sheet)); gint x, y; // use this to get the scroll x value to align the header gdk_window_get_position (sheet_layout_win, &x, &y); cairo_set_source_surface (cr, GNC_HEADER(header)->surface, x, 0); cairo_paint (cr); return TRUE; }
static void canvas_realize (GtkWidget *widget) { ECanvas *ecanvas = E_CANVAS (widget); GdkWindow *window; /* Chain up to parent's realize() method. */ GTK_WIDGET_CLASS (e_canvas_parent_class)->realize (widget); window = gtk_layout_get_bin_window (GTK_LAYOUT (widget)); gdk_window_set_background_pattern (window, NULL); window = gtk_widget_get_window (widget); gtk_im_context_set_client_window (ecanvas->im_context, window); }
static gboolean leave_notify_cb (GocCanvas *canvas, GdkEventCrossing* event, G_GNUC_UNUSED gpointer data) { double x, y; gboolean result = FALSE; if (event->window != gtk_layout_get_bin_window (&canvas->base)) return TRUE; x = (canvas->direction == GOC_DIRECTION_RTL)? canvas->scroll_x1 + (canvas->width - event->x) / canvas->pixels_per_unit: canvas->scroll_x1 + event->x / canvas->pixels_per_unit; y = canvas->scroll_y1 + event->y / canvas->pixels_per_unit; if (canvas->last_item) { canvas->cur_event = (GdkEvent *) event; result = GOC_ITEM_GET_CLASS (canvas->last_item)->leave_notify (canvas->last_item, x, y); canvas->last_item = NULL; return result; } canvas->cur_event = NULL; return result; }
static gboolean layout_draw_handler (GtkWidget *widget, cairo_t *cr) { GtkLayout *layout = GTK_LAYOUT (widget); GdkWindow *bin_window = gtk_layout_get_bin_window (layout); GdkRectangle clip; gint i, j, x, y; gint imin, imax, jmin, jmax; if (!gtk_cairo_should_draw_window (cr, bin_window)) return FALSE; gdk_window_get_position (bin_window, &x, &y); cairo_translate (cr, x, y); gdk_cairo_get_clip_rectangle (cr, &clip); imin = (clip.x) / 10; imax = (clip.x + clip.width + 9) / 10; jmin = (clip.y) / 10; jmax = (clip.y + clip.height + 9) / 10; for (i = imin; i < imax; i++) for (j = jmin; j < jmax; j++) if ((i + j) % 2) cairo_rectangle (cr, 10 * i, 10 * j, 1 + i % 10, 1 + j % 10); cairo_fill (cr); return FALSE; }
static gboolean button_release_cb (GocCanvas *canvas, GdkEventButton *event, G_GNUC_UNUSED gpointer data) { double x, y; GocItem *item; if (event->window != gtk_layout_get_bin_window (&canvas->base)) return TRUE; x = (canvas->direction == GOC_DIRECTION_RTL)? canvas->scroll_x1 + (canvas->width - event->x) / canvas->pixels_per_unit: canvas->scroll_x1 + event->x / canvas->pixels_per_unit; y = canvas->scroll_y1 + event->y / canvas->pixels_per_unit; item = (canvas->grabbed_item != NULL)? canvas->grabbed_item: goc_canvas_get_item_at (canvas, x, y); if (item) { gboolean result; canvas->cur_event = (GdkEvent *) event; result = GOC_ITEM_GET_CLASS (item)->button_released (item, event->button, x, y); canvas->cur_event = NULL; return result; } return FALSE; }
static gboolean on_expose_event (GtkWidget * widget, GdkEventExpose * event, gpointer *project) { cairo_t *cr; GdkWindow *gdkw; gint i; gdkw = gtk_layout_get_bin_window (GTK_LAYOUT(widget)); cr = gdk_cairo_create (gdkw); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 1); if(!layoutexp) { for(i=0;i<=MAXLEN12;i++) { if(pertchart[i].name != NULL) { drawbutton(widget,pertchart[i].name,pertchart[i].x,pertchart[i].y,pertchart[i].type,project); } } for(i=0;i<Lin;i++) { cr = gdk_cairo_create (gdkw); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 1); cairo_move_to (cr, arrow[i].x1,arrow[i].y1); cairo_line_to (cr, arrow[i].x2,arrow[i].y2); cairo_move_to (cr, arrow[i].x2,arrow[i].y2); cairo_line_to (cr, arrow[i].x3,arrow[i].y3); cairo_move_to (cr, arrow[i].x3,arrow[i].y3); cairo_line_to (cr, arrow[i].x4,arrow[i].y4); cairo_stroke_preserve (cr); cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill (cr); cairo_destroy (cr); } } else { for(i=0;i<Lin;i++) { cr = gdk_cairo_create (gdkw); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 1); cairo_move_to (cr, arrow[i].x1,arrow[i].y1); cairo_line_to (cr, arrow[i].x2,arrow[i].y2); cairo_move_to (cr, arrow[i].x2,arrow[i].y2); cairo_line_to (cr, arrow[i].x3,arrow[i].y3); cairo_move_to (cr, arrow[i].x3,arrow[i].y3); cairo_line_to (cr, arrow[i].x4,arrow[i].y4); cairo_stroke_preserve (cr); cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill (cr); cairo_destroy (cr);} } layoutexp++; return FALSE; }
static GdkWindow* preview_window(GtkWidget *widget) { return gtk_layout_get_bin_window(GTK_LAYOUT(widget)); }
static gint canvas_button_event (GtkWidget *widget, GdkEventButton *event) { GnomeCanvas *canvas; GdkWindow *bin_window; gint mask; gint retval; g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); retval = FALSE; canvas = GNOME_CANVAS (widget); bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (canvas)); d ( g_print ("button %d, event type %d, grabbed=%p, current=%p\n", event->button, event->type, canvas->grabbed_item, canvas->current_item)); /* dispatch normally regardless of the event's window if an item has has a pointer grab in effect */ if (!canvas->grabbed_item && event->window != bin_window) return retval; switch (event->button) { case 1: mask = GDK_BUTTON1_MASK; break; case 2: mask = GDK_BUTTON2_MASK; break; case 3: mask = GDK_BUTTON3_MASK; break; case 4: mask = GDK_BUTTON4_MASK; break; case 5: mask = GDK_BUTTON5_MASK; break; default: mask = 0; } switch (event->type) { case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: /* Pick the current item as if the button were not * pressed, and then process the event. */ canvas->state = event->state; pick_current_item (canvas, (GdkEvent *) event); canvas->state ^= mask; retval = canvas_emit_event (canvas, (GdkEvent *) event); break; case GDK_BUTTON_RELEASE: /* Process the event as if the button were pressed, * then repick after the button has been released. */ canvas->state = event->state; retval = canvas_emit_event (canvas, (GdkEvent *) event); event->state ^= mask; canvas->state = event->state; pick_current_item (canvas, (GdkEvent *) event); event->state ^= mask; break; default: g_return_val_if_reached (0); } return retval; }
/* * ECell::event method */ static gint ect_event (ECellView *ecell_view, GdkEvent *event, gint model_col, gint view_col, gint row, ECellFlags flags, ECellActions *actions) { GtkLayout *layout; GdkWindow *window; ECellTreeView *tree_view = (ECellTreeView *) ecell_view; ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); ETreeTableAdapter *etta = e_cell_tree_get_tree_table_adapter (ecell_view->e_table_model, row); ETreePath node = e_cell_tree_get_node (ecell_view->e_table_model, row); gint offset = offset_of_node (ecell_view->e_table_model, row); gint result; layout = GTK_LAYOUT (tree_view->canvas); window = gtk_layout_get_bin_window (layout); switch (event->type) { case GDK_BUTTON_PRESS: if (event_in_expander (event, offset, 0)) { if (e_tree_model_node_is_expandable (tree_model, node)) { gboolean expanded = e_tree_table_adapter_node_is_expanded (etta, node); gint tmp_row = row; GdkRectangle area; animate_closure_t *closure = g_new0 (animate_closure_t, 1); cairo_t *cr; gint hgt; e_table_item_get_cell_geometry ( tree_view->cell_view.e_table_item_view, &tmp_row, &view_col, &area.x, &area.y, NULL, &area.height); area.width = offset - 2; hgt = e_cell_height (ecell_view, model_col, view_col, row); if (hgt != area.height) /* Composite cells */ area.height += hgt; cr = gdk_cairo_create (window); draw_expander ( tree_view, cr, expanded ? GTK_EXPANDER_SEMI_EXPANDED : GTK_EXPANDER_SEMI_COLLAPSED, GTK_STATE_NORMAL, &area); cairo_destroy (cr); closure->ectv = tree_view; closure->etta = etta; closure->node = node; closure->expanded = expanded; closure->area = area; tree_view->animate_timeout = e_named_timeout_add ( 50, animate_expander, closure); return TRUE; } } else if (event->button.x < (offset - INDENT_AMOUNT)) return FALSE; break; case GDK_MOTION_NOTIFY: if (e_tree_model_node_is_expandable (tree_model, node)) { gint height = ect_height (ecell_view, model_col, view_col, row); GdkRectangle area; gboolean in_expander = event_in_expander (event, offset, height); if (tree_view->prelit ^ in_expander) { gint tmp_row = row; cairo_t *cr; e_table_item_get_cell_geometry ( tree_view->cell_view.e_table_item_view, &tmp_row, &view_col, &area.x, &area.y, NULL, &area.height); area.width = offset - 2; cr = gdk_cairo_create (window); draw_expander ( tree_view, cr, e_tree_table_adapter_node_is_expanded (etta, node) ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED, in_expander ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, &area); cairo_destroy (cr); tree_view->prelit = in_expander; return TRUE; } } break; case GDK_LEAVE_NOTIFY: if (tree_view->prelit) { gint tmp_row = row; GdkRectangle area; cairo_t *cr; e_table_item_get_cell_geometry ( tree_view->cell_view.e_table_item_view, &tmp_row, &view_col, &area.x, &area.y, NULL, &area.height); area.width = offset - 2; cr = gdk_cairo_create (window); draw_expander ( tree_view, cr, e_tree_table_adapter_node_is_expanded (etta, node) ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED, GTK_STATE_NORMAL, &area); cairo_destroy (cr); tree_view->prelit = FALSE; } return TRUE; default: break; } adjust_event_position (event, -offset); result = e_cell_event (tree_view->subcell_view, event, model_col, view_col, row, flags, actions); adjust_event_position (event, offset); return result; }
C4Window* C4Window::Init(WindowKind windowKind, C4AbstractApp * pApp, const char * Title, const C4Rect * size) { Active = true; #ifdef GDK_WINDOWING_X11 if(!FindFBConfig(Config.Graphics.MultiSampling, &Info)) { // Disable multisampling if we don't find a visual which // supports the currently configured setting. if(!FindFBConfig(0, &Info)) return NULL; Config.Graphics.MultiSampling = 0; } #endif assert(!window); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); if (windowKind == W_Viewport) { C4ViewportWindow * vw = static_cast<C4ViewportWindow *>(this); // Cannot just use ScrolledWindow because this would just move // the GdkWindow of the DrawingArea. GtkWidget* table = gtk_grid_new(); render_widget = gtk_drawing_area_new(); gtk_widget_set_hexpand(GTK_WIDGET(render_widget), true); gtk_widget_set_vexpand(GTK_WIDGET(render_widget), true); gtk_grid_attach(GTK_GRID(table), GTK_WIDGET(render_widget), 0, 0, 1, 1); vw->h_scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, NULL); gtk_grid_attach(GTK_GRID(table), vw->h_scrollbar, 0, 1, 1, 1); vw->v_scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, NULL); gtk_grid_attach(GTK_GRID(table), vw->v_scrollbar, 1, 0, 1, 1); GtkAdjustment* adjustment = gtk_range_get_adjustment(GTK_RANGE(vw->h_scrollbar)); g_signal_connect( G_OBJECT(adjustment), "value-changed", G_CALLBACK(OnHScrollStatic), this ); adjustment = gtk_range_get_adjustment(GTK_RANGE(vw->v_scrollbar)); g_signal_connect( G_OBJECT(adjustment), "value-changed", G_CALLBACK(OnVScrollStatic), this ); gtk_container_add(GTK_CONTAINER(window), table); gtk_widget_add_events(GTK_WIDGET(window), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK | GDK_POINTER_MOTION_MASK); gtk_drag_dest_set(GTK_WIDGET(render_widget), GTK_DEST_DEFAULT_ALL, drag_drop_entries, 1, GDK_ACTION_COPY); g_signal_connect(G_OBJECT(render_widget), "drag-data-received", G_CALLBACK(OnDragDataReceivedStatic), this); g_signal_connect(G_OBJECT(render_widget), "draw", G_CALLBACK(OnExposeStatic), this); g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(OnKeyPressStatic), this); g_signal_connect(G_OBJECT(window), "key-release-event", G_CALLBACK(OnKeyReleaseStatic), this); g_signal_connect(G_OBJECT(window), "scroll-event", G_CALLBACK(OnScrollVW), this); g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(OnButtonPressStatic), this); g_signal_connect(G_OBJECT(window), "button-release-event", G_CALLBACK(OnButtonReleaseStatic), this); g_signal_connect(G_OBJECT(window), "motion-notify-event", G_CALLBACK(OnMotionNotifyStatic), this); g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(OnKeyPress), this); g_signal_connect(G_OBJECT(window), "key-release-event", G_CALLBACK(OnKeyRelease), this); g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(OnConfigureStatic), this); g_signal_connect(G_OBJECT(window), "realize", G_CALLBACK(OnRealizeStatic), this); g_signal_connect_after(G_OBJECT(render_widget), "configure-event", G_CALLBACK(OnConfigureDareaStatic), this); #if !GTK_CHECK_VERSION(3,10,0) // do not draw the default background gtk_widget_set_double_buffered (GTK_WIDGET(render_widget), false); #endif gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(Console.window)); #if !GTK_CHECK_VERSION(3,14,0) gtk_window_set_has_resize_grip(GTK_WINDOW(window), false); #endif } else if (windowKind == W_Fullscreen) { render_widget = gtk_drawing_area_new(); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(render_widget)); g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(OnConfigureNotify), this); g_signal_connect(G_OBJECT(window), "focus-in-event", G_CALLBACK(OnFocusInFS), this); g_signal_connect(G_OBJECT(window), "focus-out-event", G_CALLBACK(OnFocusOutFS), this); g_signal_connect(G_OBJECT(window), "unmap-event", G_CALLBACK(OnFocusOutFS), this); g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(OnButtonPressFS), this); g_signal_connect(G_OBJECT(window), "button-release-event", G_CALLBACK(OnButtonRelease), this); g_signal_connect(G_OBJECT(window), "motion-notify-event", G_CALLBACK(OnMotionNotify), this); g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(OnKeyPress), this); g_signal_connect(G_OBJECT(window), "key-release-event", G_CALLBACK(OnKeyRelease), this); g_signal_connect(G_OBJECT(window), "scroll-event", G_CALLBACK(OnScroll), this); gtk_widget_add_events(GTK_WIDGET(window), GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); #if !GTK_CHECK_VERSION(3,10,0) gtk_widget_set_double_buffered (GTK_WIDGET(render_widget), false); #endif GValue val = {0,{{0}}}; g_value_init (&val, G_TYPE_BOOLEAN); g_value_set_boolean (&val, true); g_object_set_property (G_OBJECT (render_widget), "can-focus", &val); g_object_set_property (G_OBJECT (window), "can-focus", &val); g_value_unset (&val); #if !GTK_CHECK_VERSION(3,14,0) gtk_window_set_has_resize_grip(GTK_WINDOW(window), false); #endif } else if (windowKind == W_GuiWindow) { render_widget = window; g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(OnButtonPressGD), this); g_signal_connect(G_OBJECT(window), "button-release-event", G_CALLBACK(OnButtonReleaseGD), this); g_signal_connect(G_OBJECT(window), "motion-notify-event", G_CALLBACK(OnMotionNotifyGD), this); g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(OnConfigureGD), this); g_signal_connect(G_OBJECT(window), "scroll-event", G_CALLBACK(OnScroll), this); gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(Console.window)); #if !GTK_CHECK_VERSION(3,14,0) gtk_window_set_has_resize_grip(GTK_WINDOW(window), false); #endif } else if (windowKind == W_Console) { render_widget = window; } assert(window); assert(render_widget); // Override gtk's default to match name/class of the XLib windows gtk_window_set_wmclass(GTK_WINDOW(window), C4ENGINENAME, C4ENGINENAME); gtk_window_set_default_size(GTK_WINDOW(window), size->Wdt, size->Hgt); g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK(OnDelete), this); handlerDestroy = g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(OnDestroyStatic), this); gtk_widget_add_events(GTK_WIDGET(window), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_SCROLL_MASK); // TODO: It would be nice to support GDK_SCROLL_SMOOTH_MASK and // smooth scrolling for scrolling in menus, however that should not // change the scroll wheel behaviour ingame for zooming or // inventory change. Note that when both GDK_SCROLL_MASK and // GDK_SMOOTH_SCROLL_MASK are enabled, both type of scroll events // are reported, so one needs to make sure to not double-process them. // It would be nice to have smooth scrolling also e.g. for zooming // ingame, but it probably requires the notion of smooth scrolling // other parts of the engine as well. #ifdef GDK_WINDOWING_X11 GdkScreen * scr = gtk_widget_get_screen(GTK_WIDGET(render_widget)); Display * const dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default()); XVisualInfo *vis_info = glXGetVisualFromFBConfig(dpy, Info); assert(vis_info); GdkVisual * vis = gdk_x11_screen_lookup_visual(scr, vis_info->visualid); XFree(vis_info); gtk_widget_set_visual(GTK_WIDGET(render_widget),vis); #endif gtk_widget_show_all(GTK_WIDGET(window)); // XVisualInfo vitmpl; int blub; // vitmpl.visual = gdk_x11_visual_get_xvisual(gtk_widget_get_visual(window)); // vitmpl.visualid = XVisualIDFromVisual(vitmpl.visual); // Info = XGetVisualInfo(dpy, VisualIDMask, &vitmpl, &blub); // printf("%p\n", gtk_widget_get_visual(render_widget)); // Info = gdk_x11_visual_get_xvisual(gtk_widget_get_visual(render_widget)); // Default icon has been set right after gtk_init(), // so we don't need to take care about setting the icon here. SetTitle(Title); // Wait until window is mapped to get the window's XID gtk_widget_show_now(GTK_WIDGET(window)); GdkWindow* render_gdk_wnd; if (GTK_IS_LAYOUT(render_widget)) render_gdk_wnd = gtk_layout_get_bin_window(GTK_LAYOUT(render_widget)); else render_gdk_wnd = gtk_widget_get_window(GTK_WIDGET(render_widget)); #ifdef GDK_WINDOWING_X11 renderwnd = GDK_WINDOW_XID(render_gdk_wnd); #elif defined(GDK_WINDOWING_WIN32) renderwnd = reinterpret_cast<HWND>(gdk_win32_window_get_handle(render_gdk_wnd)); #endif // Make sure the window is shown and ready to be rendered into, // this avoids an async X error. gdk_flush(); if (windowKind == W_Fullscreen) gdk_window_set_cursor(gtk_widget_get_window(GTK_WIDGET(render_widget)), gdk_cursor_new_for_display(gdk_display_get_default(), GDK_BLANK_CURSOR)); return this; }