static void zbar_gtk_realize (GtkWidget *widget) { ZBarGtk *self = ZBAR_GTK(widget); if(!self->_private) return; ZBarGtkPrivate *zbar = ZBAR_GTK_PRIVATE(self->_private); GTK_WIDGET_UNSET_FLAGS(widget, GTK_DOUBLE_BUFFERED); GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); GdkWindowAttr attributes; attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = (gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK); widget->window = gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, GDK_WA_X | GDK_WA_Y); gdk_window_set_user_data(widget->window, widget); gdk_window_set_back_pixmap(widget->window, NULL, TRUE); /* attach zbar_window to underlying X window */ if(zbar_window_attach(zbar->window, gdk_x11_drawable_get_xdisplay(widget->window), gdk_x11_drawable_get_xid(widget->window))) zbar_window_error_spew(zbar->window, 0); }
static void init_graphics2d_as_renderable (struct graphics2d *gr) { Drawable draw; Display * dpy; Visual * vis; g_assert (gr != NULL); g_assert (gr->drawable != NULL); gr->drawbuf = NULL; if (gr->debug) printf ("initializing graphics2d as renderable\n"); draw = gdk_x11_drawable_get_xid (gr->drawable); dpy = gdk_x11_drawable_get_xdisplay (gr->drawable); g_assert (dpy != NULL); vis = gdk_x11_visual_get_xvisual (gdk_drawable_get_visual (gr->drawable)); g_assert (vis != NULL); gr->surface = cairo_xlib_surface_create (dpy, draw, vis, CAIRO_FORMAT_ARGB32, DefaultColormap (dpy, DefaultScreen (dpy))); g_assert (gr->surface != NULL); g_assert (gr->cr != NULL); cairo_set_target_surface (gr->cr, gr->surface); }
bool wxGetFrameExtents(GdkWindow* window, int* left, int* right, int* top, int* bottom) { #ifdef GDK_WINDOWING_X11 static GdkAtom property = gdk_atom_intern("_NET_FRAME_EXTENTS", false); Atom xproperty = gdk_x11_atom_to_xatom_for_display( gdk_drawable_get_display(window), property); Atom type; int format; gulong nitems, bytes_after; guchar* data; Status status = XGetWindowProperty( gdk_x11_drawable_get_xdisplay(window), gdk_x11_drawable_get_xid(window), xproperty, 0, 4, false, XA_CARDINAL, &type, &format, &nitems, &bytes_after, &data); const bool success = status == Success && data && nitems == 4; if (success) { long* p = (long*)data; if (left) *left = int(p[0]); if (right) *right = int(p[1]); if (top) *top = int(p[2]); if (bottom) *bottom = int(p[3]); } if (data) XFree(data); return success; #else return false; #endif }
static void _vte_pango_x_draw_text(struct _vte_draw *draw, struct _vte_draw_text_request *requests, gsize n_requests, GdkColor *color, guchar alpha) { Display *display; GC gc; struct _vte_pango_x_data *data; char buf[VTE_UTF8_BPC]; gsize i, length; GdkColor wcolor; data = (struct _vte_pango_x_data*) draw->impl_data; wcolor = *color; gdk_rgb_find_color(gdk_drawable_get_colormap(draw->widget->window), &wcolor); gdk_gc_set_foreground(data->gc, &wcolor); display = gdk_x11_drawable_get_xdisplay(draw->widget->window); gc = gdk_x11_gc_get_xgc(data->gc); for (i = 0; i < n_requests; i++) { length = g_unichar_to_utf8(requests[i].c, buf); pango_layout_set_text(data->layout, buf, length); pango_x_render_layout(display, data->drawable, gc, data->layout, requests[i].x - data->x_offs, requests[i].y - data->y_offs); } }
S9xXVDisplayDriver::S9xXVDisplayDriver (Snes9xWindow *window, Snes9xConfig *config) { this->window = window; this->config = config; this->drawing_area = GTK_WIDGET (window->drawing_area); display = gdk_x11_drawable_get_xdisplay (GDK_DRAWABLE (gtk_widget_get_window (drawing_area))); last_known_width = last_known_height = -1; return; }
static void setup_imlib_for_drawable(GdkDrawable * d) { imlib_context_set_dither(1); /* dither for depths < 24bpp */ imlib_context_set_display( gdk_x11_drawable_get_xdisplay(d)); imlib_context_set_visual( gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(d))); imlib_context_set_colormap( gdk_x11_colormap_get_xcolormap(gdk_drawable_get_colormap(d))); imlib_context_set_drawable( gdk_x11_drawable_get_xid(d)); }
gboolean sugar_key_grabber_is_modifier(SugarKeyGrabber *grabber, guint keycode, guint mask) { Display *xdisplay; XModifierKeymap *modmap; gint start, end, i, mod_index; gboolean is_modifier = FALSE; xdisplay = gdk_x11_drawable_get_xdisplay(GDK_DRAWABLE (grabber->root)); modmap = XGetModifierMapping(xdisplay); if (mask != -1) { mod_index = 0; mask = mask >> 1; while (mask != 0) { mask = mask >> 1; mod_index += 1; } start = mod_index * modmap->max_keypermod; end = (mod_index + 1) * modmap->max_keypermod; } else {
static void _vte_pango_x_start(struct _vte_draw *draw) { struct _vte_pango_x_data *data; Display *display; GdkDrawable *drawable; int x_offs, y_offs; data = (struct _vte_pango_x_data*) draw->impl_data; display = gdk_x11_drawable_get_xdisplay(draw->widget->window); if (data->ctx != NULL) { g_object_unref(data->ctx); } data->ctx = pango_x_get_context(display); if (data->layout != NULL) { g_object_unref(data->layout); } data->layout = pango_layout_new(data->ctx); if (data->font != NULL) { pango_layout_set_font_description(data->layout, data->font); } if (data->gc != NULL) { g_object_unref(data->gc); } data->gc = gdk_gc_new(draw->widget->window); gdk_rgb_find_color(gdk_drawable_get_colormap(draw->widget->window), &data->color); gdk_window_get_internal_paint_info(draw->widget->window, &drawable, &x_offs, &y_offs); data->drawable = gdk_x11_drawable_get_xid(drawable); data->x_offs = x_offs; data->y_offs = y_offs; }
static void draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, char *data) { #if 0 void *image; int w,h; printf("draw_image_warp data=%s\n", data); image = imlib_load_image(data); imlib_context_set_display(gdk_x11_drawable_get_xdisplay(gr->widget->window)); imlib_context_set_colormap(gdk_x11_colormap_get_xcolormap(gtk_widget_get_colormap(gr->widget))); imlib_context_set_visual(gdk_x11_visual_get_xvisual(gtk_widget_get_visual(gr->widget))); imlib_context_set_drawable(gdk_x11_drawable_get_xid(gr->drawable)); imlib_context_set_image(image); w = imlib_image_get_width(); h = imlib_image_get_height(); if (count == 3) { imlib_render_image_on_drawable_skewed(0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, p[1].y-p[0].y, p[2].x-p[0].x, p[2].y-p[0].y); } if (count == 2) { imlib_render_image_on_drawable_skewed(0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, 0, 0, p[1].y-p[0].y); } #endif }
static cairo_t * get_cairo_context (gamine_t *cb) { Display *dpy; Drawable xid; Visual *visual; GdkDrawable *drawable; gint x_offset, y_offset; gint width, height; cairo_surface_t *surface; cairo_t *context; if (cb->is_cairo) return cb->cr; //if (GDK_IS_WINDOW (window)) { gdk_window_get_internal_paint_info ((cb->da)->window, &drawable,&x_offset, &y_offset); //} else { // drawable = window; //}; dpy = gdk_x11_drawable_get_xdisplay (drawable); xid = gdk_x11_drawable_get_xid (drawable); gdk_drawable_get_size (drawable, &width, &height); visual = GDK_VISUAL_XVISUAL(gdk_drawable_get_visual (drawable)); //create an xlib surface surface = cairo_xlib_surface_create (dpy, xid, visual, width, height); //create context context = cairo_create (surface); //cairo_surface_destroy (surface); //if (GDK_IS_WINDOW (window)) cairo_translate (context, -x_offset, -y_offset); cb->is_cairo = TRUE; cb->cr = context; cb->surface = surface; return context; }
static cairo_t *_mt_cairo_begin(MT_TOOLKIT *mt, MT_WINDOW *win, MT_RECTANGLE *area, int x, int y, int width, int height) { GdkWindow *window = (GdkWindow *)win; GdkDrawable *drawable; cairo_t *cr; gint xoff, yoff; gint w, h; /* revert to rendering to GdkPixbuf (needed for Gecko based applications): */ if (!window || !GDK_IS_WINDOW(window)) { return _mt_cairo_begin_pixbuf(mt, win, area, x, y, width, height); } gdk_window_get_internal_paint_info(window, &drawable, &xoff, &yoff); if (!drawable) { return _mt_cairo_begin_pixbuf(mt, win, area, x, y, width, height); } gdk_drawable_get_size(drawable, &w, &h); _cairo_surface = cairo_xlib_surface_create(gdk_x11_drawable_get_xdisplay(drawable), gdk_x11_drawable_get_xid(drawable), gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(drawable)), w, h); cr = cairo_create(_cairo_surface); cairo_translate(cr, -xoff + x, -yoff + y); if (area) { cairo_rectangle(cr, area->x - x, area->y - y, area->width, area->height); cairo_clip(cr); cairo_rectangle(cr, 0, 0, width, height); cairo_clip(cr); } return cr; }
MetaWindowMenu* meta_window_menu_new (MetaFrames *frames, MetaMenuOp ops, MetaMenuOp insensitive, Window client_xwindow, unsigned long active_workspace, int n_workspaces, MetaWindowMenuFunc func, gpointer data) { int i; MetaWindowMenu *menu; /* FIXME: Modifications to 'ops' should happen in meta_window_show_menu */ if (n_workspaces < 2) ops &= ~(META_MENU_OP_STICK | META_MENU_OP_UNSTICK | META_MENU_OP_WORKSPACES); else if (n_workspaces == 2) /* #151183: If we only have two workspaces, disable the menu listing them. */ ops &= ~(META_MENU_OP_WORKSPACES); menu = g_new (MetaWindowMenu, 1); menu->frames = frames; menu->client_xwindow = client_xwindow; menu->func = func; menu->data = data; menu->ops = ops; menu->insensitive = insensitive; menu->menu = gtk_menu_new (); gtk_menu_set_screen (GTK_MENU (menu->menu), gtk_widget_get_screen (GTK_WIDGET (frames))); for (i = 0; i < (int) G_N_ELEMENTS (menuitems); i++) { MenuItem menuitem = menuitems[i]; if (ops & menuitem.op || menuitem.op == 0) { GtkWidget *mi; MenuData *md; unsigned int key; MetaVirtualModifier mods; mi = menu_item_new (&menuitem, -1); /* Set the activeness of radiobuttons. */ switch (menuitem.op) { case META_MENU_OP_STICK: gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), active_workspace == 0xFFFFFFFF); break; case META_MENU_OP_UNSTICK: gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), active_workspace != 0xFFFFFFFF); break; default: break; } if (menuitem.type == MENU_ITEM_WORKSPACE_LIST) { if (ops & META_MENU_OP_WORKSPACES) { Display *display; Window xroot; GdkScreen *screen; GtkWidget *submenu; int j; MenuItem to_another_workspace = { 0, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Another _Workspace") }; meta_verbose ("Creating %d-workspace menu current space %lu\n", n_workspaces, active_workspace); display = gdk_x11_drawable_get_xdisplay (GTK_WIDGET (frames)->window); screen = gdk_drawable_get_screen (GTK_WIDGET (frames)->window); xroot = GDK_DRAWABLE_XID (gdk_screen_get_root_window (screen)); submenu = gtk_menu_new (); g_assert (mi==NULL); mi = menu_item_new (&to_another_workspace, -1); gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), submenu); for (j = 0; j < n_workspaces; j++) { char *label; MenuData *md; unsigned int key; MetaVirtualModifier mods; MenuItem moveitem; GtkWidget *submi; meta_core_get_menu_accelerator (META_MENU_OP_WORKSPACES, j + 1, &key, &mods); label = get_workspace_name_with_accel (display, xroot, j); moveitem.type = MENU_ITEM_NORMAL; moveitem.op = META_MENU_OP_WORKSPACES; moveitem.label = label; submi = menu_item_new (&moveitem, j + 1); g_free (label); if ((active_workspace == (unsigned)j) && (ops & META_MENU_OP_UNSTICK)) gtk_widget_set_sensitive (submi, FALSE); md = g_new (MenuData, 1); md->menu = menu; md->op = META_MENU_OP_WORKSPACES; g_object_set_data (G_OBJECT (submi), "workspace", GINT_TO_POINTER (j)); gtk_signal_connect_full (GTK_OBJECT (submi), "activate", G_CALLBACK (activate_cb), NULL, md, g_free, FALSE, FALSE); gtk_menu_shell_append (GTK_MENU_SHELL (submenu), submi); gtk_widget_show (submi); } } else meta_verbose ("not creating workspace menu\n"); } else if (menuitem.type != MENU_ITEM_SEPARATOR) { meta_core_get_menu_accelerator (menuitems[i].op, -1, &key, &mods); if (insensitive & menuitem.op) gtk_widget_set_sensitive (mi, FALSE); md = g_new (MenuData, 1); md->menu = menu; md->op = menuitem.op; gtk_signal_connect_full (GTK_OBJECT (mi), "activate", G_CALLBACK (activate_cb), NULL, md, g_free, FALSE, FALSE); } if (mi) { gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), mi); gtk_widget_show (mi); } } } g_signal_connect (menu->menu, "selection_done", G_CALLBACK(menu_closed), menu); return menu; }
int S9xXVDisplayDriver::init (void) { int padding; int depth = 0, num_formats, num_attrs, highest_formats = 0; XvImageFormatValues *formats = NULL; XvAdaptorInfo *adaptors; XvAttribute *port_attr; VisualID visualid = None; unsigned int num_adaptors; GdkScreen *screen; GdkWindow *root; buffer[0] = malloc (image_padded_size); buffer[1] = malloc (scaled_padded_size); padding = (image_padded_size - image_size) / 2; padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + padding); padding = (scaled_padded_size - scaled_size) / 2; padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + padding); memset (buffer[0], 0, image_padded_size); memset (buffer[1], 0, scaled_padded_size); /* Setup XV */ gtk_widget_realize (drawing_area); display = gdk_x11_drawable_get_xdisplay (GDK_DRAWABLE (gtk_widget_get_window (drawing_area))); screen = gtk_widget_get_screen (drawing_area); root = gdk_screen_get_root_window (screen); xv_portid = -1; XvQueryAdaptors (display, GDK_WINDOW_XWINDOW (root), &num_adaptors, &adaptors); for (int i = 0; i < (int) num_adaptors; i++) { if (adaptors[i].type & XvInputMask && adaptors[i].type & XvImageMask) { formats = XvListImageFormats (display, adaptors[i].base_id, &num_formats); if (num_formats > highest_formats) { xv_portid = adaptors[i].base_id; highest_formats = num_formats; visualid = adaptors[i].formats->visual_id; } free (formats); } } XvFreeAdaptorInfo (adaptors); if (xv_portid < 0) { fprintf (stderr, "Could not open Xv output port.\n"); return -1; } /* Set XV_AUTOPAINT_COLORKEY _only_ if available */ port_attr = XvQueryPortAttributes (display, xv_portid, &num_attrs); for (int i = 0; i < num_attrs; i++) { if (!strcmp (port_attr[i].name, "XV_AUTOPAINT_COLORKEY")) { Atom colorkey = None; colorkey = XInternAtom (display, "XV_AUTOPAINT_COLORKEY", True); if (colorkey != None) XvSetPortAttribute (display, xv_portid, colorkey, 1); } } /* Try to find an RGB format */ format = FOURCC_YUY2; bpp = 100; formats = XvListImageFormats (display, xv_portid, &num_formats); for (int i = 0; i < num_formats; i++) { if (formats[i].id == 0x3 || formats[i].type == XvRGB) { if (formats[i].bits_per_pixel < bpp) { format = formats[i].id; bpp = formats[i].bits_per_pixel; bytes_per_pixel = (bpp == 15) ? 2 : bpp >> 3; depth = formats[i].depth; this->rshift = get_inv_shift (formats[i].red_mask, bpp); this->gshift = get_inv_shift (formats[i].green_mask, bpp); this->bshift = get_inv_shift (formats[i].blue_mask, bpp); /* Check for red-blue inversion on SiliconMotion drivers */ if (formats[i].red_mask == 0x001f && formats[i].blue_mask == 0x7c00) { int copy = this->rshift; this->rshift = this->bshift; this->bshift = copy; } /* on big-endian Xv still seems to like LSB order */ if (config->force_inverted_byte_order) S9xSetEndianess (ENDIAN_MSB); else S9xSetEndianess (ENDIAN_LSB); } } }
bool wxTopLevelWindowGTK::Show( bool show ) { wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); bool deferShow = show && !m_isShown && m_deferShow; if (deferShow) { deferShow = gs_requestFrameExtentsStatus != 2 && m_deferShowAllowed && !gtk_widget_get_realized(m_widget); if (deferShow) { deferShow = g_signal_handler_find(m_widget, GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA), g_signal_lookup("property_notify_event", GTK_TYPE_WIDGET), 0, NULL, NULL, this) != 0; } GdkScreen* screen = NULL; if (deferShow) { #ifdef GDK_WINDOWING_X11 screen = gtk_widget_get_screen(m_widget); GdkAtom atom = gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false); deferShow = gdk_x11_screen_supports_net_wm_hint(screen, atom) != 0; #else deferShow = false; #endif // If _NET_REQUEST_FRAME_EXTENTS not supported, don't allow changes // to m_decorSize, it breaks saving/restoring window size with // GetSize()/SetSize() because it makes window bigger between each // restore and save. m_updateDecorSize = deferShow; } m_deferShow = deferShow; } if (deferShow) { // Initial show. If WM supports _NET_REQUEST_FRAME_EXTENTS, defer // calling gtk_widget_show() until _NET_FRAME_EXTENTS property // notification is received, so correct frame extents are known. // This allows resizing m_widget to keep the overall size in sync with // what wxWidgets expects it to be without an obvious change in the // window size immediately after it becomes visible. // Realize m_widget, so m_widget->window can be used. Realizing normally // causes the widget tree to be size_allocated, which generates size // events in the wrong order. However, the size_allocates will not be // done if the allocation is not the default (1,1). GtkAllocation alloc; gtk_widget_get_allocation(m_widget, &alloc); const int alloc_width = alloc.width; if (alloc_width == 1) { alloc.width = 2; gtk_widget_set_allocation(m_widget, &alloc); } gtk_widget_realize(m_widget); if (alloc_width == 1) { alloc.width = 1; gtk_widget_set_allocation(m_widget, &alloc); } #ifdef GDK_WINDOWING_X11 // send _NET_REQUEST_FRAME_EXTENTS XClientMessageEvent xevent; memset(&xevent, 0, sizeof(xevent)); xevent.type = ClientMessage; GdkWindow* window = gtk_widget_get_window(m_widget); xevent.window = gdk_x11_drawable_get_xid(window); xevent.message_type = gdk_x11_atom_to_xatom_for_display( gdk_drawable_get_display(window), gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false)); xevent.format = 32; Display* display = gdk_x11_drawable_get_xdisplay(window); XSendEvent(display, DefaultRootWindow(display), false, SubstructureNotifyMask | SubstructureRedirectMask, (XEvent*)&xevent); #endif // GDK_WINDOWING_X11 if (gs_requestFrameExtentsStatus == 0) { // if WM does not respond to request within 1 second, // we assume support for _NET_REQUEST_FRAME_EXTENTS is not working m_netFrameExtentsTimerId = g_timeout_add(1000, request_frame_extents_timeout, this); } // defer calling gtk_widget_show() m_isShown = true; return true; } if (show && !gtk_widget_get_realized(m_widget)) { // size_allocate signals occur in reverse order (bottom to top). // Things work better if the initial wxSizeEvents are sent (from the // top down), before the initial size_allocate signals occur. wxSizeEvent event(GetSize(), GetId()); event.SetEventObject(this); HandleWindowEvent(event); } bool change = base_type::Show(show); if (change && !show) { // make sure window has a non-default position, so when it is shown // again, it won't be repositioned by WM as if it were a new window // Note that this must be done _after_ the window is hidden. gtk_window_move((GtkWindow*)m_widget, m_x, m_y); } return change; }