// helper: return the GtkSettings either for the screen the current window is // on or for the default screen if window is NULL static GtkSettings *GetSettingsForWindowScreen(GdkWindow *window) { return window ? gtk_settings_get_for_screen(gdk_drawable_get_screen(window)) : gtk_settings_get_default(); }
static void gtku_gl_drawing_area_realize (GtkWidget * widget) { GtkuGLDrawingArea * self = GTKU_GL_DRAWING_AREA (widget); GtkuGLDrawingAreaPrivate * priv = GTKU_GL_DRAWING_AREA_GET_PRIVATE (self); /* chain up */ GTK_WIDGET_CLASS (gtku_gl_drawing_area_parent_class)->realize (widget); priv->dpy = GDK_WINDOW_XDISPLAY(widget->window); #if 0 priv->visual = glXChooseVisual (priv->dpy, GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (GDK_DRAWABLE (widget->window))), //DefaultScreen (priv->dpy), attr_list); #endif GdkDrawable * draw = GDK_DRAWABLE (widget->window); int screen = GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (draw)); XVisualInfo vinfo_template = { .visualid = XVisualIDFromVisual (gdk_x11_visual_get_xvisual ( gdk_drawable_get_visual (draw))), .screen = screen, .depth = gdk_drawable_get_depth (draw), }; int nitems; fprintf (stderr, "Using X Visual 0x%x\n", (unsigned int) vinfo_template.visualid); priv->visual = XGetVisualInfo (priv->dpy, VisualIDMask | VisualScreenMask | VisualDepthMask, &vinfo_template, &nitems); if (priv->visual == NULL) { g_warning ("Failed to find GLX visual\n"); return; } if (nitems != 1) fprintf (stderr, "Warning: more than one matching X visual found\n"); priv->context = glXCreateContext (priv->dpy, priv->visual, 0, GL_TRUE); if (!priv->context) { g_warning ("Failed to get GLX context\n"); XFree (priv->visual); priv->visual = NULL; return; } if (!glXMakeCurrent (priv->dpy, GDK_WINDOW_XID (widget->window), priv->context)) { g_warning ("Could not make GLX context current\n"); return; } /* If the user doesn't want vblank sync, we are done */ if (!self->vblank_sync) return; /* Check for the presence of the video_sync extension */ if (!is_glx_extension_present (priv->dpy, screen, "GLX_SGI_video_sync")) { self->vblank_sync = 0; fprintf (stderr, "Video sync functions not found, disabling...\n"); return; } #ifdef USE_VBLANK /* Below we create a new thread to monitor the vblank. We will * signal back to this thread by writing to a file descriptor * when each vblank occurs. */ /* TODO: check extension list */ GetVideoSyncSGI = (PFNGLXGETVIDEOSYNCSGIPROC) glXGetProcAddressARB ( (unsigned char *)"glXGetVideoSyncSGI"); WaitVideoSyncSGI = (PFNGLXWAITVIDEOSYNCSGIPROC) glXGetProcAddressARB ( (unsigned char *)"glXWaitVideoSyncSGI"); if (!GetVideoSyncSGI || !WaitVideoSyncSGI) { self->vblank_sync = 0; fprintf (stderr, "Video sync functions not found, disabling...\n"); return; } unsigned int count = 0; if (GetVideoSyncSGI (&count) != 0) { self->vblank_sync = 0; fprintf (stderr, "Video sync counter failed, disabling...\n"); return; } int pp = pipe (priv->pipe); assert (pp >= 0); fcntl (priv->pipe[0], F_SETFL, O_NONBLOCK); if (pthread_create (&priv->thread, NULL, swap_thread, priv) != 0) { self->vblank_sync = 0; fprintf (stderr, "Video sync thread creation failed, disabling...\n"); return; } GIOChannel * chan = g_io_channel_unix_new (priv->pipe[0]); priv->vblank_watch = g_io_add_watch (chan, G_IO_IN, swap_func, self); g_io_channel_unref (chan); #endif }
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 wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win ) { guchar *data = NULL; Atom type; int format; gulong nitems; GdkWindow *window = NULL; if(win && GTK_WIDGET_REALIZED(win->GetHandle())) window = win->GetHandle()->window; switch (index) { case wxSYS_BORDER_X: case wxSYS_BORDER_Y: case wxSYS_EDGE_X: case wxSYS_EDGE_Y: case wxSYS_FRAMESIZE_X: case wxSYS_FRAMESIZE_Y: // If a window is specified/realized, and it is a toplevel window, we can query from wm. // The returned border thickness is outside the client area in that case. if (window) { wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow); if (!tlw) return -1; // not a tlw, not sure how to approach else { // Check if wm supports frame extents - we can't know // the border widths if it does not. #if GTK_CHECK_VERSION(2,2,0) if (!gtk_check_version(2,2,0)) { if (!gdk_x11_screen_supports_net_wm_hint( gdk_drawable_get_screen(window), gdk_atom_intern("_NET_FRAME_EXTENTS", false) ) ) return -1; } else #endif { if (!gdk_net_wm_supports(gdk_atom_intern("_NET_FRAME_EXTENTS", false))) return -1; } // Get the frame extents from the windowmanager. // In most cases the top extent is the titlebar, so we use the bottom extent // for the heights. if (wxXGetWindowProperty(window, type, format, nitems, data)) { int border_return = -1; if ((type == XA_CARDINAL) && (format == 32) && (nitems >= 4) && (data)) { switch(index) { case wxSYS_BORDER_X: case wxSYS_EDGE_X: case wxSYS_FRAMESIZE_X: border_return = ((long*)data)[1]; // width of right extent break; default: border_return = ((long*)data)[3]; // height of bottom extent break; } } if (data) XFree(data); return border_return; } } } return -1; // no window specified case wxSYS_CURSOR_X: case wxSYS_CURSOR_Y: #ifdef __WXGTK24__ if (!gtk_check_version(2,4,0)) { if (window) return gdk_display_get_default_cursor_size(gdk_drawable_get_display(window)); else return gdk_display_get_default_cursor_size(gdk_display_get_default()); } else #endif return 16; case wxSYS_DCLICK_X: case wxSYS_DCLICK_Y: gint dclick_distance; #if GTK_CHECK_VERSION(2,2,0) if (window && !gtk_check_version(2,2,0)) g_object_get(gtk_settings_get_for_screen(gdk_drawable_get_screen(window)), "gtk-double-click-distance", &dclick_distance, NULL); else #endif g_object_get(gtk_settings_get_default(), "gtk-double-click-distance", &dclick_distance, NULL); return dclick_distance * 2; case wxSYS_DRAG_X: case wxSYS_DRAG_Y: gint drag_threshold; #if GTK_CHECK_VERSION(2,2,0) if (window && !gtk_check_version(2,2,0)) { g_object_get( gtk_settings_get_for_screen(gdk_drawable_get_screen(window)), "gtk-dnd-drag-threshold", &drag_threshold, NULL); } else #endif { g_object_get(gtk_settings_get_default(), "gtk-dnd-drag-threshold", &drag_threshold, NULL); } // The correct thing here would be to double the value // since that is what the API wants. But the values // are much bigger under GNOME than under Windows and // just seem to much in many cases to be useful. // drag_threshold *= 2; return drag_threshold; // MBN: ditto for icons case wxSYS_ICON_X: return 32; case wxSYS_ICON_Y: return 32; case wxSYS_SCREEN_X: #if GTK_CHECK_VERSION(2,2,0) if (window && !gtk_check_version(2,2,0)) return gdk_screen_get_width(gdk_drawable_get_screen(window)); else #endif return gdk_screen_width(); case wxSYS_SCREEN_Y: #if GTK_CHECK_VERSION(2,2,0) if (window && !gtk_check_version(2,2,0)) return gdk_screen_get_height(gdk_drawable_get_screen(window)); else #endif return gdk_screen_height(); case wxSYS_HSCROLL_Y: return 15; case wxSYS_VSCROLL_X: return 15; case wxSYS_CAPTION_Y: if (!window) // No realized window specified, and no implementation for that case yet. return -1; // Check if wm supports frame extents - we can't know the caption height if it does not. #if GTK_CHECK_VERSION(2,2,0) if (!gtk_check_version(2,2,0)) { if (!gdk_x11_screen_supports_net_wm_hint( gdk_drawable_get_screen(window), gdk_atom_intern("_NET_FRAME_EXTENTS", false) ) ) return -1; } else #endif { if (!gdk_net_wm_supports(gdk_atom_intern("_NET_FRAME_EXTENTS", false))) return -1; } wxASSERT_MSG( wxDynamicCast(win, wxTopLevelWindow), wxT("Asking for caption height of a non toplevel window") ); // Get the height of the top windowmanager border. // This is the titlebar in most cases. The titlebar might be elsewhere, and // we could check which is the thickest wm border to decide on which side the // titlebar is, but this might lead to interesting behaviours in used code. // Reconsider when we have a way to report to the user on which side it is. if (wxXGetWindowProperty(window, type, format, nitems, data)) { int caption_height = -1; if ((type == XA_CARDINAL) && (format == 32) && (nitems >= 3) && (data)) { caption_height = ((long*)data)[2]; // top frame extent } if (data) XFree(data); return caption_height; } // Try a default approach without a window pointer, if possible // ... return -1; case wxSYS_PENWINDOWS_PRESENT: // No MS Windows for Pen computing extension available in X11 based gtk+. return 0; default: return -1; // metric is unknown } }
static void on_calendar_realized(GtkWidget *widget, gpointer data) { gint parent_x, parent_y, parent_w, parent_h; gint root_w, root_h; gint width, height, x, y; gint orientation; GdkScreen *screen; GtkWidget *parent; GtkRequisition requisition; orientation = GPOINTER_TO_INT(data); parent = g_object_get_data(G_OBJECT(widget), "calendar-parent"); gdk_window_get_origin(GDK_WINDOW(parent->window), &parent_x, &parent_y); gdk_drawable_get_size(GDK_DRAWABLE(parent->window), &parent_w, &parent_h); screen = gdk_drawable_get_screen(GDK_DRAWABLE(widget->window)); root_w = gdk_screen_get_width(GDK_SCREEN(screen)); root_h = gdk_screen_get_height(GDK_SCREEN(screen)); gtk_widget_size_request(GTK_WIDGET(widget), &requisition); width = requisition.width; height = requisition.height; /* g_print("parent: %dx%d +%d+%d\n", parent_w, parent_h, parent_x, parent_y); g_print("root: %dx%d\n", root_w, root_h); g_print("calendar: %dx%d\n", width, height); */ if (orientation == GTK_ORIENTATION_VERTICAL) { if (parent_x < root_w / 2) { if (parent_y < root_h / 2) { /* upper left */ x = parent_x + parent_w; y = parent_y; } else { /* lower left */ x = parent_x + parent_w; y = parent_y + parent_h - height; } } else { if (parent_y < root_h / 2) { /* upper right */ x = parent_x - width; y = parent_y; } else { /* lower right */ x = parent_x - width; y = parent_y + parent_h - height; } } } else { if (parent_x < root_w / 2) { if (parent_y < root_h / 2) { /* upper left */ x = parent_x; y = parent_y + parent_h; } else { /* lower left */ x = parent_x; y = parent_y - height; } } else { if (parent_y < root_h / 2) { /* upper right */ x = parent_x + parent_w - width; y = parent_y + parent_h; } else { /* lower right */ x = parent_x + parent_w - width; y = parent_y - height; } } } gtk_window_move(GTK_WINDOW(widget), x, y); }
static void gtk_text_render_state_update (GtkTextRenderState *state, GtkTextAppearance *new_appearance) { GdkScreen *screen = gtk_widget_get_screen (state->widget); if (!state->last_appearance || !gdk_color_equal (&new_appearance->fg_color, &state->last_appearance->fg_color)) gtk_text_render_state_set_color (state, state->fg_gc, &new_appearance->fg_color); if (!state->last_appearance || new_appearance->fg_stipple != state->last_appearance->fg_stipple) { if (new_appearance->fg_stipple) { if (screen == gdk_drawable_get_screen (new_appearance->fg_stipple)) { gdk_gc_set_fill (state->fg_gc, GDK_STIPPLED); gdk_gc_set_stipple (state->fg_gc, new_appearance->fg_stipple); } else g_warning ("gtk_text_render_state_update:\n" "The foreground stipple bitmap has been created on the wrong screen.\n" "Ignoring the stipple bitmap information."); } else { gdk_gc_set_fill (state->fg_gc, GDK_SOLID); } } if (new_appearance->draw_bg) { if (!state->last_bg_appearance || !gdk_color_equal (&new_appearance->bg_color, &state->last_bg_appearance->bg_color)) gtk_text_render_state_set_color (state, state->bg_gc, &new_appearance->bg_color); if (!state->last_bg_appearance || new_appearance->bg_stipple != state->last_bg_appearance->bg_stipple) { if (new_appearance->bg_stipple) { if (screen == gdk_drawable_get_screen (new_appearance->bg_stipple)) { gdk_gc_set_fill (state->bg_gc, GDK_STIPPLED); gdk_gc_set_stipple (state->bg_gc, new_appearance->bg_stipple); } else g_warning ("gtk_text_render_state_update:\n" "The background stipple bitmap has been created on the wrong screen.\n" "Ignoring the stipple bitmap information."); } else { gdk_gc_set_fill (state->bg_gc, GDK_SOLID); } } state->last_bg_appearance = new_appearance; } state->last_appearance = new_appearance; }
/* Add notification action */ void add_notification_action(GtkWindow *nw, const char *text, const char *key, ActionInvokedCb cb) { WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata"); GtkWidget *label; GtkWidget *button; GtkWidget *hbox; GdkPixbuf *pixbuf; char *buf; g_assert(windata != NULL); if (!GTK_WIDGET_VISIBLE(windata->actions_box)) { GtkWidget *alignment; gtk_widget_show(windata->actions_box); alignment = gtk_alignment_new(1, 0.5, 0, 0); gtk_widget_show(alignment); gtk_box_pack_end(GTK_BOX(windata->actions_box), alignment, FALSE, TRUE, 0); windata->pie_countdown = gtk_drawing_area_new(); gtk_widget_show(windata->pie_countdown); gtk_container_add(GTK_CONTAINER(alignment), windata->pie_countdown); gtk_widget_set_size_request(windata->pie_countdown, PIE_WIDTH, PIE_HEIGHT); g_signal_connect(G_OBJECT(windata->pie_countdown), "expose_event", G_CALLBACK(countdown_expose_cb), windata); } button = gtk_button_new(); gtk_widget_show(button); gtk_box_pack_start(GTK_BOX(windata->actions_box), button, FALSE, FALSE, 0); hbox = gtk_hbox_new(FALSE, 6); gtk_widget_show(hbox); gtk_container_add(GTK_CONTAINER(button), hbox); /* Try to be smart and find a suitable icon. */ buf = g_strdup_printf("stock_%s", key); pixbuf = gtk_icon_theme_load_icon( gtk_icon_theme_get_for_screen( gdk_drawable_get_screen(GTK_WIDGET(nw)->window)), buf, 16, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); g_free(buf); if (pixbuf != NULL) { GtkWidget *image = gtk_image_new_from_pixbuf(pixbuf); gtk_widget_show(image); gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.5); } label = gtk_label_new(NULL); gtk_widget_show(label); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); buf = g_strdup_printf("<small>%s</small>", text); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); g_object_set_data(G_OBJECT(button), "_nw", nw); g_object_set_data_full(G_OBJECT(button), "_action_key", g_strdup(key), g_free); g_signal_connect(G_OBJECT(button), "button-release-event", G_CALLBACK(action_clicked_cb), cb); }
void render_text(GdkDrawable *da, GdkGC *gc, int x, int y, double angle, const char *s, const char *font, double xalign, double yalign, int xmax, int ymax) { GdkScreen *screen; PangoRenderer *renderer; PangoContext *context; PangoLayout *layout; PangoFontDescription *desc; int width, height; PangoMatrix m = PANGO_MATRIX_INIT; double f_min, f; /* set up the renderer */ screen = gdk_drawable_get_screen(da); renderer = gdk_pango_renderer_get_default(screen); gdk_pango_renderer_set_drawable(GDK_PANGO_RENDERER(renderer), da); gdk_pango_renderer_set_gc(GDK_PANGO_RENDERER(renderer), gc); /* start preparing the layout */ context = gdk_pango_context_get_for_screen(screen); layout = pango_layout_new(context); pango_layout_set_text(layout, s, -1); /* apply the font */ desc = pango_font_description_from_string(font); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); /* align and position the text */ pango_layout_get_size(layout, &width, &height); f_min = 1.0; if (xmax) { f = xmax/((double) width/PANGO_SCALE); if (f < f_min) f_min = f; } if (ymax) { f = ymax/((double) height/PANGO_SCALE); if (f < f_min) f_min = f; } if (f_min < MIN_FONT_SCALE) f_min = MIN_FONT_SCALE; pango_matrix_translate(&m, x, y); pango_matrix_rotate(&m, angle); pango_matrix_translate(&m, -xalign*f_min*width/PANGO_SCALE, (yalign-1)*f_min*height/PANGO_SCALE); pango_matrix_scale(&m, f_min, f_min); pango_context_set_matrix(context, &m); pango_layout_context_changed(layout); pango_renderer_draw_layout(renderer, layout, 0, 0); /* clean up renderer */ gdk_pango_renderer_set_drawable(GDK_PANGO_RENDERER(renderer), NULL); gdk_pango_renderer_set_gc(GDK_PANGO_RENDERER(renderer), NULL); /* free objects */ g_object_unref(layout); g_object_unref(context); }
static VALUE rg_screen(VALUE self) { return GOBJ2RVAL(gdk_drawable_get_screen(_SELF(self))); }
static void thunar_icon_renderer_render (GtkCellRenderer *renderer, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags) { ThunarClipboardManager *clipboard; ThunarFileIconState icon_state; ThunarIconRenderer *icon_renderer = THUNAR_ICON_RENDERER (renderer); ThunarIconFactory *icon_factory; GtkIconSource *icon_source; GtkIconTheme *icon_theme; GdkRectangle emblem_area; GdkRectangle icon_area; GdkRectangle draw_area; GtkStateType state; GdkPixbuf *emblem; GdkPixbuf *icon; GdkPixbuf *temp; GList *emblems; GList *lp; gint max_emblems; gint position; if (G_UNLIKELY (icon_renderer->file == NULL)) return; /* determine the icon state */ icon_state = (icon_renderer->drop_file != icon_renderer->file) ? renderer->is_expanded ? THUNAR_FILE_ICON_STATE_OPEN : THUNAR_FILE_ICON_STATE_DEFAULT : THUNAR_FILE_ICON_STATE_DROP; /* load the main icon */ icon_theme = gtk_icon_theme_get_for_screen (gdk_drawable_get_screen (window)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); icon = thunar_icon_factory_load_file_icon (icon_factory, icon_renderer->file, icon_state, icon_renderer->size); if (G_UNLIKELY (icon == NULL)) { g_object_unref (G_OBJECT (icon_factory)); return; } /* pre-light the item if we're dragging about it */ if (G_UNLIKELY (icon_state == THUNAR_FILE_ICON_STATE_DROP)) flags |= GTK_CELL_RENDERER_PRELIT; /* determine the real icon size */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); /* scale down the icon on-demand */ if (G_UNLIKELY (icon_area.width > cell_area->width || icon_area.height > cell_area->height)) { /* scale down to fit */ temp = exo_gdk_pixbuf_scale_down (icon, TRUE, cell_area->width, cell_area->height); g_object_unref (G_OBJECT (icon)); icon = temp; /* determine the icon dimensions again */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); } icon_area.x = cell_area->x + (cell_area->width - icon_area.width) / 2; icon_area.y = cell_area->y + (cell_area->height - icon_area.height) / 2; /* check whether the icon is affected by the expose event */ if (gdk_rectangle_intersect (expose_area, &icon_area, &draw_area)) { /* use a translucent icon to represent cutted and hidden files to the user */ clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (widget)); if (thunar_clipboard_manager_has_cutted_file (clipboard, icon_renderer->file)) { /* 50% translucent for cutted files */ temp = exo_gdk_pixbuf_lucent (icon, 50); g_object_unref (G_OBJECT (icon)); icon = temp; } else if (thunar_file_is_hidden (icon_renderer->file)) { /* 75% translucent for hidden files */ temp = exo_gdk_pixbuf_lucent (icon, 75); g_object_unref (G_OBJECT (icon)); icon = temp; } g_object_unref (G_OBJECT (clipboard)); /* colorize the icon if we should follow the selection state */ if ((flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_PRELIT)) != 0 && icon_renderer->follow_state) { if ((flags & GTK_CELL_RENDERER_SELECTED) != 0) { state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE; temp = exo_gdk_pixbuf_colorize (icon, &widget->style->base[state]); g_object_unref (G_OBJECT (icon)); icon = temp; } if ((flags & GTK_CELL_RENDERER_PRELIT) != 0) { temp = exo_gdk_pixbuf_spotlight (icon); g_object_unref (G_OBJECT (icon)); icon = temp; } } /* check if we should render an insensitive icon */ if (G_UNLIKELY (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE || !renderer->sensitive)) { /* allocate an icon source */ icon_source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (icon_source, icon); gtk_icon_source_set_size_wildcarded (icon_source, FALSE); gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_SMALL_TOOLBAR); /* render the insensitive icon */ temp = gtk_style_render_icon (widget->style, icon_source, gtk_widget_get_direction (widget), GTK_STATE_INSENSITIVE, -1, widget, "gtkcellrendererpixbuf"); g_object_unref (G_OBJECT (icon)); icon = temp; /* release the icon source */ gtk_icon_source_free (icon_source); } /* render the invalid parts of the icon */ gdk_draw_pixbuf (window, widget->style->black_gc, icon, draw_area.x - icon_area.x, draw_area.y - icon_area.y, draw_area.x, draw_area.y, draw_area.width, draw_area.height, GDK_RGB_DITHER_NORMAL, 0, 0); } /* release the file's icon */ g_object_unref (G_OBJECT (icon)); /* check if we should render emblems as well */ if (G_LIKELY (icon_renderer->emblems)) { /* display the primary emblem as well (if any) */ emblems = thunar_file_get_emblem_names (icon_renderer->file); if (G_UNLIKELY (emblems != NULL)) { /* render up to four emblems for sizes from 48 onwards, else up to 2 emblems */ max_emblems = (icon_renderer->size < 48) ? 2 : 4; /* render the emblems */ for (lp = emblems, position = 0; lp != NULL && position < max_emblems; lp = lp->next) { /* check if we have the emblem in the icon theme */ emblem = thunar_icon_factory_load_icon (icon_factory, lp->data, icon_renderer->size, NULL, FALSE); if (G_UNLIKELY (emblem == NULL)) continue; /* determine the dimensions of the emblem */ emblem_area.width = gdk_pixbuf_get_width (emblem); emblem_area.height = gdk_pixbuf_get_height (emblem); /* shrink insane emblems */ if (G_UNLIKELY (MAX (emblem_area.width, emblem_area.height) > (gint) MIN ((2 * icon_renderer->size) / 3, 36))) { /* scale down the emblem */ temp = exo_gdk_pixbuf_scale_ratio (emblem, MIN ((2 * icon_renderer->size) / 3, 36)); g_object_unref (G_OBJECT (emblem)); emblem = temp; /* determine the size again */ emblem_area.width = gdk_pixbuf_get_width (emblem); emblem_area.height = gdk_pixbuf_get_height (emblem); } /* determine a good position for the emblem, depending on the position index */ switch (position) { case 0: /* right/bottom */ emblem_area.x = MIN (icon_area.x + icon_area.width - emblem_area.width / 2, cell_area->x + cell_area->width - emblem_area.width); emblem_area.y = MIN (icon_area.y + icon_area.height - emblem_area.height / 2, cell_area->y + cell_area->height -emblem_area.height); break; case 1: /* left/bottom */ emblem_area.x = MAX (icon_area.x - emblem_area.width / 2, cell_area->x); emblem_area.y = MIN (icon_area.y + icon_area.height - emblem_area.height / 2, cell_area->y + cell_area->height -emblem_area.height); break; case 2: /* left/top */ emblem_area.x = MAX (icon_area.x - emblem_area.width / 2, cell_area->x); emblem_area.y = MAX (icon_area.y - emblem_area.height / 2, cell_area->y); break; case 3: /* right/top */ emblem_area.x = MIN (icon_area.x + icon_area.width - emblem_area.width / 2, cell_area->x + cell_area->width - emblem_area.width); emblem_area.y = MAX (icon_area.y - emblem_area.height / 2, cell_area->y); break; default: _thunar_assert_not_reached (); } /* render the emblem */ if (gdk_rectangle_intersect (expose_area, &emblem_area, &draw_area)) { gdk_draw_pixbuf (window, widget->style->black_gc, emblem, draw_area.x - emblem_area.x, draw_area.y - emblem_area.y, draw_area.x, draw_area.y, draw_area.width, draw_area.height, GDK_RGB_DITHER_NORMAL, 0, 0); } /* release the emblem */ g_object_unref (G_OBJECT (emblem)); /* advance the position index */ ++position; } /* release the emblem name list */ g_list_free (emblems); } } /* release our reference on the icon factory */ g_object_unref (G_OBJECT (icon_factory)); }
int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win ) { GdkWindow *window = NULL; if (win) window = gtk_widget_get_window(win->GetHandle()); switch (index) { case wxSYS_BORDER_X: case wxSYS_BORDER_Y: case wxSYS_EDGE_X: case wxSYS_EDGE_Y: case wxSYS_FRAMESIZE_X: case wxSYS_FRAMESIZE_Y: if (win) { wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow); if (!tlw) return GetBorderWidth(index, win); else if (window) { // Get the frame extents from the windowmanager. // In most cases the top extent is the titlebar, so we use the bottom extent // for the heights. int right, bottom; if (wxGetFrameExtents(window, NULL, &right, NULL, &bottom)) { switch (index) { case wxSYS_BORDER_X: case wxSYS_EDGE_X: case wxSYS_FRAMESIZE_X: return right; // width of right extent default: return bottom; // height of bottom extent } } } } return -1; // no window specified case wxSYS_CURSOR_X: case wxSYS_CURSOR_Y: return gdk_display_get_default_cursor_size( window ? gdk_drawable_get_display(window) : gdk_display_get_default()); case wxSYS_DCLICK_X: case wxSYS_DCLICK_Y: gint dclick_distance; g_object_get(GetSettingsForWindowScreen(window), "gtk-double-click-distance", &dclick_distance, NULL); return dclick_distance * 2; case wxSYS_DCLICK_MSEC: gint dclick; g_object_get(GetSettingsForWindowScreen(window), "gtk-double-click-time", &dclick, NULL); return dclick; case wxSYS_DRAG_X: case wxSYS_DRAG_Y: gint drag_threshold; g_object_get(GetSettingsForWindowScreen(window), "gtk-dnd-drag-threshold", &drag_threshold, NULL); // The correct thing here would be to double the value // since that is what the API wants. But the values // are much bigger under GNOME than under Windows and // just seem to much in many cases to be useful. // drag_threshold *= 2; return drag_threshold; case wxSYS_ICON_X: case wxSYS_ICON_Y: return 32; case wxSYS_SCREEN_X: if (window) return gdk_screen_get_width(gdk_drawable_get_screen(window)); else return gdk_screen_width(); case wxSYS_SCREEN_Y: if (window) return gdk_screen_get_height(gdk_drawable_get_screen(window)); else return gdk_screen_height(); case wxSYS_HSCROLL_Y: case wxSYS_VSCROLL_X: return 15; case wxSYS_CAPTION_Y: if (!window) // No realized window specified, and no implementation for that case yet. return -1; wxASSERT_MSG( wxDynamicCast(win, wxTopLevelWindow), wxT("Asking for caption height of a non toplevel window") ); // Get the height of the top windowmanager border. // This is the titlebar in most cases. The titlebar might be elsewhere, and // we could check which is the thickest wm border to decide on which side the // titlebar is, but this might lead to interesting behaviours in used code. // Reconsider when we have a way to report to the user on which side it is. { int top; if (wxGetFrameExtents(window, NULL, NULL, &top, NULL)) { return top; // top frame extent } } // Try a default approach without a window pointer, if possible // ... return -1; case wxSYS_PENWINDOWS_PRESENT: // No MS Windows for Pen computing extension available in X11 based gtk+. return 0; default: return -1; // metric is unknown } }
gboolean gdk_gl_window_make_context_current (GdkGLDrawable *draw, GdkGLContext *glcontext) { GdkGLDrawable *read = draw; GdkGLConfig *glconfig; Window glxwindow; GLXContext glxcontext; g_return_val_if_fail (GDK_IS_GL_WINDOW (draw), FALSE); g_return_val_if_fail (GDK_IS_GL_CONTEXT_IMPL_X11 (glcontext), FALSE); glconfig = GDK_GL_WINDOW (draw)->glconfig; glxwindow = GDK_GL_WINDOW (draw)->glxwindow; glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (glcontext); if (glxwindow == None || glxcontext == NULL) return FALSE; GDK_GL_NOTE (MISC, g_message (" -- Window: screen number = %d", GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (GDK_DRAWABLE (draw))))); GDK_GL_NOTE (MISC, g_message (" -- Window: visual id = 0x%lx", GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (GDK_DRAWABLE (draw)))->visualid)); GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent"); if (!glXMakeCurrent (GDK_GL_CONFIG_XDISPLAY (glconfig), glxwindow, glxcontext)) { g_warning ("glXMakeCurrent() failed"); _gdk_gl_context_set_gl_drawable (glcontext, NULL); return FALSE; } _gdk_gl_context_set_gl_drawable (glcontext, draw); if (_GDK_GL_CONFIG_AS_SINGLE_MODE (glconfig)) { /* We do this because we are treating a double-buffered frame buffer as a single-buffered frame buffer because the system does not appear to export any suitable single-buffered visuals (in which the following are necessary). */ glDrawBuffer (GL_FRONT); glReadBuffer (GL_FRONT); } GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ()); return TRUE; }