void gdk_gl_texture_quads (GdkGLContext *paint_context, guint texture_target, int n_quads, GdkTexturedQuad *quads) { GdkGLContextPaintData *paint_data = gdk_gl_context_get_paint_data (paint_context); GdkGLContextProgram *program; GdkWindow *window = gdk_gl_context_get_window (paint_context); int window_scale = gdk_window_get_scale_factor (window); float w = gdk_window_get_width (window) * window_scale; float h = gdk_window_get_height (window) * window_scale; int i; float *vertex_buffer_data; bind_vao (paint_data); if (paint_data->tmp_vertex_buffer == 0) glGenBuffers(1, &paint_data->tmp_vertex_buffer); if (texture_target == GL_TEXTURE_RECTANGLE_ARB) use_texture_rect_program (paint_data); else use_texture_2d_program (paint_data); program = paint_data->current_program; glActiveTexture (GL_TEXTURE0); glUniform1i(program->map_location, 0); /* Use texture unit 0 */ glEnableVertexAttribArray (program->position_location); glEnableVertexAttribArray (program->uv_location); glBindBuffer (GL_ARRAY_BUFFER, paint_data->tmp_vertex_buffer); glVertexAttribPointer (program->position_location, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, NULL); glVertexAttribPointer (program->uv_location, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, (void *) (sizeof(float) * 2)); #define VERTEX_SIZE 4 #define QUAD_N_VERTICES 6 #define QUAD_SIZE (VERTEX_SIZE * QUAD_N_VERTICES) vertex_buffer_data = g_new (float, n_quads * QUAD_SIZE); for (i = 0; i < n_quads; i++) { GdkTexturedQuad *quad = &quads[i]; float vertex_data[] = { (quad->x1 * 2) / w - 1, (quad->y1 * 2) / h - 1, quad->u1, quad->v1, (quad->x1 * 2) / w - 1, (quad->y2 * 2) / h - 1, quad->u1, quad->v2, (quad->x2 * 2) / w - 1, (quad->y1 * 2) / h - 1, quad->u2, quad->v1, (quad->x2 * 2) / w - 1, (quad->y2 * 2) / h - 1, quad->u2, quad->v2, (quad->x1 * 2) / w - 1, (quad->y2 * 2) / h - 1, quad->u1, quad->v2, (quad->x2 * 2) / w - 1, (quad->y1 * 2) / h - 1, quad->u2, quad->v1, }; float *vertex = &vertex_buffer_data[i * QUAD_SIZE]; memcpy (vertex, vertex_data, sizeof(vertex_data)); } glBufferData (GL_ARRAY_BUFFER, sizeof(float) * n_quads * QUAD_SIZE, vertex_buffer_data, GL_STREAM_DRAW); glDrawArrays (GL_TRIANGLES, 0, n_quads * QUAD_N_VERTICES); g_free (vertex_buffer_data); glDisableVertexAttribArray (program->position_location); glDisableVertexAttribArray (program->uv_location); }
static void gd_tagged_entry_tag_get_relative_allocations (GdTaggedEntryTag *tag, GdTaggedEntry *entry, GtkStyleContext *context, GtkAllocation *background_allocation_out, GtkAllocation *layout_allocation_out, GtkAllocation *button_allocation_out) { GtkAllocation background_allocation, layout_allocation, button_allocation; gint width, height, x, y, pix_width, pix_height; gint layout_width, layout_height; gint scale_factor; GtkBorder padding, border; GtkStateFlags state; width = gdk_window_get_width (tag->window); height = gdk_window_get_height (tag->window); scale_factor = gdk_window_get_scale_factor (tag->window); state = gd_tagged_entry_tag_get_state (tag, entry); gtk_style_context_get_margin (context, state, &padding); width -= padding.left + padding.right; height -= padding.top + padding.bottom; x = padding.left; y = padding.top; background_allocation.x = x; background_allocation.y = y; background_allocation.width = width; background_allocation.height = height; layout_allocation = button_allocation = background_allocation; gtk_style_context_get_padding (context, state, &padding); gtk_style_context_get_border (context, state, &border); gd_tagged_entry_tag_ensure_layout (tag, entry); pango_layout_get_pixel_size (tag->layout, &layout_width, &layout_height); layout_allocation.x += border.left + padding.left; layout_allocation.y += (layout_allocation.height - layout_height) / 2; if (entry->button_visible && tag->has_close_button) { pix_width = cairo_image_surface_get_width (tag->close_surface) / scale_factor; pix_height = cairo_image_surface_get_height (tag->close_surface) / scale_factor; } else { pix_width = 0; pix_height = 0; } button_allocation.x += width - pix_width - border.right - padding.right; button_allocation.y += (height - pix_height) / 2; button_allocation.width = pix_width; button_allocation.height = pix_height; if (background_allocation_out) *background_allocation_out = background_allocation; if (layout_allocation_out) *layout_allocation_out = layout_allocation; if (button_allocation_out) *button_allocation_out = button_allocation; }
/** * shell_tray_icon_click: * @icon: a #ShellTrayIcon * @event: the #ClutterEvent triggering the fake click * * Fakes a press and release on @icon. @event must be a * %CLUTTER_BUTTON_RELEASE event. Its relevant details will be passed * on to the icon, but its coordinates will be ignored; the click is * always made on the center of @icon. */ void shell_tray_icon_click (ShellTrayIcon *icon, ClutterEvent *event) { XKeyEvent xkevent; XButtonEvent xbevent; XCrossingEvent xcevent; GdkWindow *remote_window; GdkScreen *screen; int x_root, y_root; Display *xdisplay; Window xwindow, xrootwindow; ClutterEventType event_type = clutter_event_type (event); g_return_if_fail (event_type == CLUTTER_BUTTON_RELEASE || event_type == CLUTTER_KEY_RELEASE); gdk_error_trap_push (); remote_window = gtk_socket_get_plug_window (GTK_SOCKET (icon->priv->socket)); xwindow = GDK_WINDOW_XID (remote_window); xdisplay = GDK_WINDOW_XDISPLAY (remote_window); screen = gdk_window_get_screen (remote_window); xrootwindow = GDK_WINDOW_XID (gdk_screen_get_root_window (screen)); gdk_window_get_origin (remote_window, &x_root, &y_root); /* First make the icon believe the pointer is inside it */ xcevent.type = EnterNotify; xcevent.window = xwindow; xcevent.root = xrootwindow; xcevent.subwindow = None; xcevent.time = clutter_event_get_time (event); xcevent.x = gdk_window_get_width (remote_window) / 2; xcevent.y = gdk_window_get_height (remote_window) / 2; xcevent.x_root = x_root + xcevent.x; xcevent.y_root = y_root + xcevent.y; xcevent.mode = NotifyNormal; xcevent.detail = NotifyNonlinear; xcevent.same_screen = True; XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xcevent); /* Now do the click */ if (event_type == CLUTTER_BUTTON_RELEASE) { xbevent.window = xwindow; xbevent.root = xrootwindow; xbevent.subwindow = None; xbevent.time = xcevent.time; xbevent.x = xcevent.x; xbevent.y = xcevent.y; xbevent.x_root = xcevent.x_root; xbevent.y_root = xcevent.y_root; xbevent.state = clutter_event_get_state (event); xbevent.same_screen = True; xbevent.type = ButtonPress; xbevent.button = clutter_event_get_button (event); XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xbevent); xbevent.type = ButtonRelease; XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xbevent); } else { xkevent.window = xwindow; xkevent.root = xrootwindow; xkevent.subwindow = None; xkevent.time = xcevent.time; xkevent.x = xcevent.x; xkevent.y = xcevent.y; xkevent.x_root = xcevent.x_root; xkevent.y_root = xcevent.y_root; xkevent.state = clutter_event_get_state (event); xkevent.same_screen = True; xkevent.type = KeyPress; xkevent.keycode = clutter_event_get_key_code (event); XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent); xkevent.type = KeyRelease; XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent); } /* And move the pointer back out */ xcevent.type = LeaveNotify; XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xcevent); gdk_error_trap_pop_ignored (); }
static void _lib_geotagging_show_offset_window(GtkWidget *widget, dt_lib_module_t *self) { dt_lib_geotagging_t *d = self->data; gint x, y; gint px, py, center_w, center_h, window_w, window_h; GtkWidget *window = dt_ui_main_window(darktable.gui->ui); GtkWidget *center = dt_ui_center(darktable.gui->ui); gdk_window_get_origin(gtk_widget_get_window(center), &px, &py); center_w = gdk_window_get_width(gtk_widget_get_window(center)); center_h = gdk_window_get_height(gtk_widget_get_window(center)); d->floating_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_can_focus(d->floating_window, TRUE); gtk_window_set_decorated(GTK_WINDOW(d->floating_window), FALSE); gtk_window_set_type_hint(GTK_WINDOW(d->floating_window), GDK_WINDOW_TYPE_HINT_POPUP_MENU); gtk_window_set_transient_for(GTK_WINDOW(d->floating_window), GTK_WINDOW(window)); gtk_widget_set_opacity(d->floating_window, 0.8); gtk_window_set_modal(GTK_WINDOW(d->floating_window), TRUE); GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); gtk_widget_set_margin_top(vbox, DT_PIXEL_APPLY_DPI(2)); gtk_widget_set_margin_bottom(vbox, DT_PIXEL_APPLY_DPI(5)); gtk_widget_set_margin_start(vbox, DT_PIXEL_APPLY_DPI(5)); gtk_widget_set_margin_end(vbox, DT_PIXEL_APPLY_DPI(5)); gtk_container_add(GTK_CONTAINER(d->floating_window), vbox); d->floating_window_entry = gtk_entry_new(); gtk_widget_add_events(d->floating_window_entry, GDK_FOCUS_CHANGE_MASK); g_signal_connect_swapped(d->floating_window, "focus-out-event", G_CALLBACK(gtk_widget_destroy), d->floating_window); g_object_set(G_OBJECT(d->floating_window_entry), "tooltip-text", _("enter the time shown on the selected picture\nformat: hh:mm:ss"), (char *)NULL); gtk_editable_select_region(GTK_EDITABLE(d->floating_window_entry), 0, -1); gtk_box_pack_start(GTK_BOX(vbox), d->floating_window_entry, TRUE, TRUE, 0); g_signal_connect(d->floating_window_entry, "key-press-event", G_CALLBACK(_lib_geotagging_floating_key_press), self); GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); GtkWidget *cancel_button = gtk_button_new_with_label(_("cancel")); GtkWidget *ok_button = gtk_button_new_with_label(_("ok")); gtk_box_pack_start(GTK_BOX(hbox), cancel_button, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), ok_button, TRUE, TRUE, 0); g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", G_CALLBACK(gtk_widget_destroy), d->floating_window); g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(_lib_geotagging_calculate_offset_callback), self); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); gtk_widget_show_all(d->floating_window); gtk_widget_grab_focus(d->floating_window_entry); window_w = gdk_window_get_width(gtk_widget_get_window(d->floating_window)); window_h = gdk_window_get_height(gtk_widget_get_window(d->floating_window)); x = px + 0.5 * (center_w - window_w); y = py + center_h - 20 - window_h; gtk_window_move(GTK_WINDOW(d->floating_window), x, y); gtk_window_present(GTK_WINDOW(d->floating_window)); }
static void render (GtkWidget * widget) { GSMColorButton *color_button = GSM_COLOR_BUTTON (widget); GdkColor *color, tmp_color = color_button->priv->color; color = &tmp_color; cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); cairo_path_t *path = NULL; gint width, height; gdouble radius, arc_start, arc_end; gint highlight_factor; if (color_button->priv->highlight > 0) { highlight_factor = 8192 * color_button->priv->highlight; if (color->red + highlight_factor > 65535) color->red = 65535; else color->red = color->red + highlight_factor; if (color->blue + highlight_factor > 65535) color->blue = 65535; else color->blue = color->blue + highlight_factor; if (color->green + highlight_factor > 65535) color->green = 65535; else color->green = color->green + highlight_factor; } gdk_cairo_set_source_color (cr, color); #if GTK_CHECK_VERSION(3, 0, 0) width = gdk_window_get_width(gtk_widget_get_window(widget)); height = gdk_window_get_height(gtk_widget_get_window(widget)); #else gdk_drawable_get_size(gtk_widget_get_window(widget), &width, &height); #endif switch (color_button->priv->type) { case GSMCP_TYPE_CPU: //gtk_widget_set_size_request (widget, GSMCP_MIN_WIDTH, GSMCP_MIN_HEIGHT); cairo_paint (cr); cairo_set_line_width (cr, 1); cairo_set_source_rgba (cr, 0, 0, 0, 0.5); cairo_rectangle (cr, 0.5, 0.5, width - 1, height - 1); cairo_stroke (cr); cairo_set_line_width (cr, 1); cairo_set_source_rgba (cr, 1, 1, 1, 0.4); cairo_rectangle (cr, 1.5, 1.5, width - 3, height - 3); cairo_stroke (cr); break; case GSMCP_TYPE_PIE: if (width < 32) // 32px minimum size gtk_widget_set_size_request (widget, 32, 32); if (width < height) radius = width / 2; else radius = height / 2; arc_start = -G_PI_2 + 2 * G_PI * color_button->priv->fraction; arc_end = -G_PI_2; cairo_set_line_width (cr, 1); // Draw external stroke and fill if (color_button->priv->fraction < 0.01) { cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 4.5, 0, 2 * G_PI); } else if (color_button->priv->fraction > 0.99) { cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25, 0, 2 * G_PI); } else { cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25, arc_start, arc_end); cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 4.5, arc_end, arc_start); cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25, arc_start, arc_start); } cairo_fill_preserve (cr); cairo_set_source_rgba (cr, 0, 0, 0, 0.7); cairo_stroke (cr); // Draw internal highlight cairo_set_source_rgba (cr, 1, 1, 1, 0.45); cairo_set_line_width (cr, 1); if (color_button->priv->fraction < 0.03) { cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 3.25, 0, 2 * G_PI); } else if (color_button->priv->fraction > 0.99) { cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5, 0, 2 * G_PI); } else { cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5, arc_start + (1 / (radius - 3.75)), arc_end - (1 / (radius - 3.75))); cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 3.25, arc_end - (1 / (radius - 3.75)), arc_start + (1 / (radius - 3.75))); cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5, arc_start + (1 / (radius - 3.75)), arc_start + (1 / (radius - 3.75))); } cairo_stroke (cr); // Draw external shape cairo_set_line_width (cr, 1); cairo_set_source_rgba (cr, 0, 0, 0, 0.2); cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 1.25, 0, G_PI * 2); cairo_stroke (cr); break; case GSMCP_TYPE_NETWORK_IN: if (color_button->priv->image_buffer == NULL) color_button->priv->image_buffer = fill_image_buffer_from_file (cr, DATADIR "/pixmaps/mate-system-monitor/download.svg"); gtk_widget_set_size_request (widget, 32, 32); cairo_move_to (cr, 8.5, 1.5); cairo_line_to (cr, 23.5, 1.5); cairo_line_to (cr, 23.5, 11.5); cairo_line_to (cr, 29.5, 11.5); cairo_line_to (cr, 16.5, 27.5); cairo_line_to (cr, 15.5, 27.5); cairo_line_to (cr, 2.5, 11.5); cairo_line_to (cr, 8.5, 11.5); cairo_line_to (cr, 8.5, 1.5); cairo_close_path (cr); path = cairo_copy_path (cr); cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); cairo_set_line_width (cr, 1); cairo_fill_preserve (cr); cairo_set_miter_limit (cr, 5.0); cairo_stroke (cr); cairo_set_source_rgba (cr, 0, 0, 0, 0.5); cairo_append_path (cr, path); cairo_path_destroy(path); cairo_stroke (cr); cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0, 0.0); cairo_paint (cr); break; case GSMCP_TYPE_NETWORK_OUT: if (color_button->priv->image_buffer == NULL) color_button->priv->image_buffer = fill_image_buffer_from_file (cr, DATADIR "/pixmaps/mate-system-monitor/upload.svg"); gtk_widget_set_size_request (widget, 32, 32); cairo_move_to (cr, 16.5, 1.5); cairo_line_to (cr, 29.5, 17.5); cairo_line_to (cr, 23.5, 17.5); cairo_line_to (cr, 23.5, 27.5); cairo_line_to (cr, 8.5, 27.5); cairo_line_to (cr, 8.5, 17.5); cairo_line_to (cr, 2.5, 17.5); cairo_line_to (cr, 15.5, 1.5); cairo_line_to (cr, 16.5, 1.5); cairo_close_path (cr); path = cairo_copy_path (cr); cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); cairo_set_line_width (cr, 1); cairo_fill_preserve (cr); cairo_set_miter_limit (cr, 5.0); cairo_stroke (cr); cairo_set_source_rgba (cr, 0, 0, 0, 0.5); cairo_append_path (cr, path); cairo_path_destroy(path); cairo_stroke (cr); cairo_set_source_surface (cr, color_button->priv->image_buffer, 0.0, 0.0); cairo_paint (cr); break; } cairo_destroy (cr); }
void gdk_wayland_window_invalidate_for_new_frame (GdkWindow *window, cairo_region_t *update_area) { cairo_rectangle_int_t window_rect; GdkDisplay *display = gdk_window_get_display (window); GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); GdkWaylandGLContext *context_wayland; int buffer_age; gboolean invalidate_all; EGLSurface egl_surface; /* Minimal update is ok if we're not drawing with gl */ if (window->gl_paint_context == NULL) return; context_wayland = GDK_WAYLAND_GL_CONTEXT (window->gl_paint_context); buffer_age = 0; egl_surface = gdk_wayland_window_get_egl_surface (window->impl_window, context_wayland->egl_config); if (display_wayland->have_egl_buffer_age) { gdk_gl_context_make_current (window->gl_paint_context); eglQuerySurface (display_wayland->egl_display, egl_surface, EGL_BUFFER_AGE_EXT, &buffer_age); } invalidate_all = FALSE; if (buffer_age == 0 || buffer_age >= 4) invalidate_all = TRUE; else { if (buffer_age >= 2) { if (window->old_updated_area[0]) cairo_region_union (update_area, window->old_updated_area[0]); else invalidate_all = TRUE; } if (buffer_age >= 3) { if (window->old_updated_area[1]) cairo_region_union (update_area, window->old_updated_area[1]); else invalidate_all = TRUE; } } if (invalidate_all) { window_rect.x = 0; window_rect.y = 0; window_rect.width = gdk_window_get_width (window); window_rect.height = gdk_window_get_height (window); /* If nothing else is known, repaint everything so that the back * buffer is fully up-to-date for the swapbuffer */ cairo_region_union_rectangle (update_area, &window_rect); } }
void gimp_overlay_child_size_allocate (GimpOverlayBox *box, GimpOverlayChild *child) { GtkWidget *widget; GtkAllocation allocation; GtkRequisition child_requisition; GtkAllocation child_allocation; gint x; gint y; g_return_if_fail (GIMP_IS_OVERLAY_BOX (box)); g_return_if_fail (child != NULL); widget = GTK_WIDGET (box); gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_child_requisition (child->widget, &child_requisition); child_allocation.x = 0; child_allocation.y = 0; child_allocation.width = child_requisition.width; child_allocation.height = child_requisition.height; gtk_widget_size_allocate (child->widget, &child_allocation); gtk_widget_get_allocation (child->widget, &child_allocation); if (gtk_widget_get_realized (GTK_WIDGET (widget))) { GdkRectangle old_allocation; GdkRectangle old_bounds; gdk_window_get_position (child->window, &old_allocation.x, &old_allocation.y); old_allocation.width = gdk_window_get_width (child->window); old_allocation.height = gdk_window_get_height (child->window); gimp_overlay_child_transform_bounds (child, &old_allocation, &old_bounds); gdk_window_invalidate_rect (gtk_widget_get_window (widget), &old_bounds, FALSE); gdk_window_move_resize (child->window, child_allocation.x, child_allocation.y, child_allocation.width, child_allocation.height); } cairo_matrix_init_identity (&child->matrix); /* local transform */ cairo_matrix_rotate (&child->matrix, child->angle); if (child->has_position) { x = child->x; y = child->y; } else { GdkRectangle bounds; gint border; gint available_width; gint available_height; gimp_overlay_child_transform_bounds (child, &child_allocation, &bounds); border = gtk_container_get_border_width (GTK_CONTAINER (box)); available_width = allocation.width - 2 * border; available_height = allocation.height - 2 * border; x = border; y = border; if (available_width > bounds.width) x += child->xalign * (available_width - bounds.width) - bounds.x; if (available_height > bounds.height) y += child->yalign * (available_height - bounds.height) - bounds.y; } cairo_matrix_init_translate (&child->matrix, x, y); /* local transform */ cairo_matrix_rotate (&child->matrix, child->angle); }
void wxGTKCairoDCImpl::InitSize(GdkWindow* window) { m_size.x = gdk_window_get_width(window); m_size.y = gdk_window_get_height(window); }
static gboolean gtk_offscreen_box_draw (GtkWidget *widget, cairo_t *cr) { GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget); GdkWindow *window; window = gtk_widget_get_window (widget); if (gtk_cairo_should_draw_window (cr, window)) { cairo_surface_t *surface; GtkAllocation child_area; if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1)) { surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window1); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); gtk_widget_get_allocation (offscreen_box->child1, &child_area); cairo_translate (cr, 0, child_area.height); } if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2)) { surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2); gtk_widget_get_allocation (offscreen_box->child2, &child_area); /* transform */ cairo_translate (cr, child_area.width / 2, child_area.height / 2); cairo_rotate (cr, offscreen_box->angle); cairo_translate (cr, -child_area.width / 2, -child_area.height / 2); /* paint */ cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); } } else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window1)) { gtk_render_background (gtk_widget_get_style_context (widget), cr, 0, 0, gdk_window_get_width (offscreen_box->offscreen_window1), gdk_window_get_height (offscreen_box->offscreen_window1)); if (offscreen_box->child1) gtk_container_propagate_draw (GTK_CONTAINER (widget), offscreen_box->child1, cr); } else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window2)) { gtk_render_background (gtk_widget_get_style_context (widget), cr, 0, 0, gdk_window_get_width (offscreen_box->offscreen_window2), gdk_window_get_height (offscreen_box->offscreen_window2)); if (offscreen_box->child2) gtk_container_propagate_draw (GTK_CONTAINER (widget), offscreen_box->child2, cr); } return FALSE; }
static gboolean _lib_tagging_tag_show(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, GdkModifierType modifier, dt_lib_module_t *self) { int mouse_over_id = -1; int zoom = dt_conf_get_int("plugins/lighttable/images_in_row"); // the order is: // if(zoom == 1) => currently shown image // else if(selection not empty) => selected images // else if(cursor over image) => hovered image // else => return if(zoom == 1 || dt_collection_get_selected_count(darktable.collection) == 0) { mouse_over_id = dt_control_get_mouse_over_id(); if(mouse_over_id < 0) return TRUE; } dt_lib_tagging_t *d = (dt_lib_tagging_t *)self->data; d->floating_tag_imgid = mouse_over_id; gint x, y; gint px, py, w, h; GtkWidget *window = dt_ui_main_window(darktable.gui->ui); GtkWidget *center = dt_ui_center(darktable.gui->ui); gdk_window_get_origin(gtk_widget_get_window(center), &px, &py); w = gdk_window_get_width(gtk_widget_get_window(center)); h = gdk_window_get_height(gtk_widget_get_window(center)); x = px + 0.5 * (w - FLOATING_ENTRY_WIDTH); y = py + h - 50; /* put the floating box at the mouse pointer */ // gint pointerx, pointery; // GdkDevice *device = // gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(widget))); // gdk_window_get_device_position (gtk_widget_get_window (widget), device, &pointerx, &pointery, NULL); // x = px + pointerx + 1; // y = py + pointery + 1; d->floating_tag_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* stackoverflow.com/questions/1925568/how-to-give-keyboard-focus-to-a-pop-up-gtk-window */ gtk_widget_set_can_focus(d->floating_tag_window, TRUE); gtk_window_set_decorated(GTK_WINDOW(d->floating_tag_window), FALSE); gtk_window_set_type_hint(GTK_WINDOW(d->floating_tag_window), GDK_WINDOW_TYPE_HINT_POPUP_MENU); gtk_window_set_transient_for(GTK_WINDOW(d->floating_tag_window), GTK_WINDOW(window)); gtk_widget_set_opacity(d->floating_tag_window, 0.8); gtk_window_move(GTK_WINDOW(d->floating_tag_window), x, y); GtkWidget *entry = gtk_entry_new(); gtk_widget_set_size_request(entry, FLOATING_ENTRY_WIDTH, -1); gtk_widget_add_events(entry, GDK_FOCUS_CHANGE_MASK); GtkEntryCompletion *completion = gtk_entry_completion_new(); gtk_entry_completion_set_model(completion, gtk_tree_view_get_model(GTK_TREE_VIEW(d->related))); gtk_entry_completion_set_text_column(completion, 0); gtk_entry_completion_set_inline_completion(completion, TRUE); gtk_entry_completion_set_popup_set_width(completion, FALSE); gtk_entry_set_completion(GTK_ENTRY(entry), completion); gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1); gtk_container_add(GTK_CONTAINER(d->floating_tag_window), entry); g_signal_connect_swapped(entry, "focus-out-event", G_CALLBACK(gtk_widget_destroy), d->floating_tag_window); g_signal_connect(entry, "key-press-event", G_CALLBACK(_lib_tagging_tag_key_press), self); gtk_widget_show_all(d->floating_tag_window); gtk_widget_grab_focus(entry); gtk_window_present(GTK_WINDOW(d->floating_tag_window)); return TRUE; }
static void create_win_message(char *icon, char *text, int duration) { GtkWidget *gwin_message = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip(GTK_WINDOW(gwin_message), FALSE); gtk_container_set_border_width (GTK_CONTAINER (gwin_message), 0); gtk_widget_realize (gwin_message); GdkWindow *gdkwin = gtk_widget_get_window(gwin_message); set_no_focus(gwin_message); GtkWidget *hbox = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (gwin_message), hbox); if (icon[0] != '-') { GtkWidget *image = gtk_image_new_from_file(icon); if (text[0] == '-') { #if GTK_CHECK_VERSION(2,91,0) GdkPixbuf *pixbuf = NULL; GdkPixbufAnimation *anime = NULL; switch(gtk_image_get_storage_type(GTK_IMAGE(image))) { case GTK_IMAGE_PIXBUF: pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); break; case GTK_IMAGE_ANIMATION: anime = gtk_image_get_animation(GTK_IMAGE(image)); pixbuf = gdk_pixbuf_animation_get_static_image(anime); break; default: break; } cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); cairo_t *cr = cairo_create(img); gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); cairo_paint(cr); cairo_region_t *mask = gdk_cairo_region_create_from_surface(img); gtk_widget_shape_combine_region(gwin_message, mask); cairo_region_destroy(mask); cairo_destroy(cr); cairo_surface_destroy(img); #else GdkBitmap *bitmap = NULL; gdk_pixbuf_render_pixmap_and_mask(gdk_pixbuf_new_from_file(icon, NULL), NULL, &bitmap, 128); gtk_widget_shape_combine_mask(gwin_message, bitmap, 0, 0); #endif } gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); } if (text[0] != '-') { GtkWidget *label = gtk_label_new(text); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); } gtk_widget_show_all(gwin_message); int width, height; get_win_size(gwin_message, &width, &height); int ox=-1, oy; int szx, szy; if (tray_da_win) { gdk_window_get_origin (tray_da_win, &ox, &oy); #if !GTK_CHECK_VERSION(2,91,0) gdk_drawable_get_size(tray_da_win, &szx, &szy); #else szx = gdk_window_get_width(tray_da_win); szy = gdk_window_get_height(tray_da_win); #endif if (oy<height) { oy = szy; } else { oy -= height; if (oy + height > dpy_yl) oy = dpy_yl - height; if (oy < 0) oy = 0; } if (ox + width > dpy_xl) ox = dpy_xl - width; if (ox < 0) ox = 0; } else if (icon_main) { GdkRectangle rect; GtkOrientation ori; if (gtk_status_icon_get_geometry(icon_main, NULL, &rect, &ori)) { dbg("rect %d,%d\n", rect.x, rect.y, rect.width, rect.height); if (ori==GTK_ORIENTATION_HORIZONTAL) { ox=rect.x; if (rect.y > 100) oy=rect.y - height; else oy=rect.y + rect.height; } else { oy=rect.y; if (rect.x > 100) ox=rect.x - width; else ox=rect.x + rect.width; } } } if (ox < 0) { ox = dpy_xl - width; oy = dpy_yl - height; } gtk_window_move(GTK_WINDOW(gwin_message), ox, oy); g_timeout_add(duration, (GSourceFunc)timeout_destroy_window, gwin_message); }
static VALUE rg_width(VALUE self) { return INT2NUM(gdk_window_get_width(_SELF(self))); }