/* ================================== ProfileWindow::make_busy_cursor ================================== */ void ProfileWindow::make_busy_cursor(bool busy) { { Glib::Mutex::Lock lock(mutex); GdkDisplay* display; GdkCursor* cursor; GdkWindow* window; display = gdk_display_get_default(); if(busy) cursor = gdk_cursor_new(GDK_WATCH); else cursor = gdk_cursor_new(GDK_LEFT_PTR); window = (GdkWindow*) profilewindow->get_window()->gobj(); gdk_window_set_cursor(window, cursor); window = (GdkWindow*) prof->get_window()->gobj(); if(!busy && (fencetoggleprof->get_active() || rulertoggle->get_active())) { gdk_cursor_unref(cursor); cursor = gdk_cursor_new(GDK_CROSSHAIR); } gdk_window_set_cursor(window, cursor); gdk_cursor_unref(cursor); gdk_display_sync(display); } }
static VkResult gdk_x11_vulkan_context_create_surface (GdkVulkanContext *context, VkSurfaceKHR *surface) { GdkSurface *window = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context)); GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context)); /* This is necessary so that Vulkan sees the Window. * Usually, vkCreateXlibSurfaceKHR() will not cause a problem to happen as * it just creates resources, but futher calls with the resulting surface * do cause issues. */ gdk_display_sync (display); return GDK_VK_CHECK (vkCreateXlibSurfaceKHR, gdk_vulkan_context_get_instance (context), &(VkXlibSurfaceCreateInfoKHR) { VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, NULL, 0, gdk_x11_display_get_xdisplay (display), gdk_x11_surface_get_xid (window) }, NULL, surface); }
static void ui_change_cursor(gboolean busy) { static GdkWindow *window; if (busy) { GdkDisplay *display; GdkCursor *cursor; // gint x, y; cursor = gdk_cursor_new (GDK_WATCH); display = gdk_display_get_default (); window = gtk_widget_get_window (GTK_WIDGET(ui_main_data.window)); // window = gdk_display_get_window_at_pointer(display, &x, &y); gdk_window_set_cursor (window, cursor); gdk_display_sync (display); g_object_unref (cursor); // gtk_widget_set_sensitive (ui_main_data.window, FALSE); ui_gtk_flush_events (); } else { gdk_window_set_cursor (window, NULL); // gtk_widget_set_sensitive (ui_main_data.window, TRUE); ui_gtk_flush_events (); } }
static void kill_window (WnckWindow *win) { WnckApplication *app; app = wnck_window_get_application (win); if (app) { gchar buf[257], *client_machine; int pid; pid = wnck_application_get_pid (app); client_machine = get_client_machine (wnck_application_get_xid (app)); if (client_machine && pid > 0) { if (gethostname (buf, sizeof (buf) - 1) == 0) { if (strcmp (buf, client_machine) == 0) kill (pid, 9); } } if (client_machine) g_free (client_machine); } gdk_error_trap_push (); XKillClient (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), wnck_window_get_xid (win)); gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop_ignored (); }
static VkResult gdk_win32_vulkan_context_create_surface (GdkVulkanContext *context, VkSurfaceKHR *surface) { GdkWindow *window = gdk_draw_context_get_window (GDK_DRAW_CONTEXT (context)); GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context)); VkWin32SurfaceCreateInfoKHR info; info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; info.pNext = NULL; info.flags = 0; info.hinstance = _gdk_dll_hinstance; info.hwnd = GDK_WINDOW_HWND (window); /* This is necessary so that Vulkan sees the Window. * Usually, vkCreateWin32SurfaceKHR() will not cause a problem to happen as * it just creates resources, but futher calls with the resulting surface * do cause issues. */ gdk_display_sync (display); return GDK_VK_CHECK (vkCreateWin32SurfaceKHR, gdk_vulkan_context_get_instance (context), &info, NULL, surface); }
int xdevice_get_last_tool_id (int deviceid) { Atom prop; Atom act_type; int act_format; unsigned long nitems, bytes_after; unsigned char *data, *ptr; int id; id = 0x0; gdk_display_sync (gdk_display_get_default ()); prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), WACOM_SERIAL_IDS_PROP, False); if (!prop) return id; gdk_error_trap_push (); if (!XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceid, prop, 0, 1000, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) == Success) { gdk_error_trap_pop_ignored (); return 0x0; } if (gdk_error_trap_pop ()) goto out; if (nitems != 4) goto out; if (act_type != XA_INTEGER) goto out; if (act_format != 32) goto out; /* item 0 = tablet ID * item 1 = old device serial number (== last tool in proximity) * item 2 = old hardware serial number (including tool ID) * item 3 = current serial number (0 if no tool in proximity) */ ptr = data; ptr += act_format/8 * 2; id = *((int32_t*)ptr); id = id & 0xfffff; /* That means that no tool was set down yet */ if (id == STYLUS_DEVICE_ID || id == ERASER_DEVICE_ID) return 0x0; out: XFree (data); return id; }
/* ================================== FileSaver::on_filesaverdialogresponse If Save button has been pressed creates a SaveWorker which saves selected flightline. ================================== */ void FileSaver::on_filesaverdialogresponse(int response_id) { if(response_id == Gtk::RESPONSE_CLOSE) { //filesaverdialog->set_filename(""); filesaverdialog->hide_all(); } else if(response_id == 1) { if (lidardata==NULL) return; if (saveworker != NULL) return; double scale_factor[3]; if (!btnUseDefault->get_active()) { const char* temp; temp = scaleFactorEntryX->get_text().c_str(); scale_factor[0] = atof(temp); temp = scaleFactorEntryY->get_text().c_str(); scale_factor[1] = atof(temp); temp = scaleFactorEntryZ->get_text().c_str(); scale_factor[2] = atof(temp); } else { scale_factor[0] = scale_factor[1] = scale_factor[2] = 0; } // tdo and prof should have the same pointbucket mutex Glib::Mutex* pbkt_mutex = tdo->getPointBucketMutex(); saveworker = new SaveWorker(this, filesaverdialog->get_filename(), lidardata->getFileName(flightlinesaveselect->get_value_as_int()), flightlinesaveselect->get_value_as_int(), parsestringentry->get_text(), latlongselect->get_active(), btnUseDefault->get_active(), scale_factor, pbkt_mutex); saveworker->start(); saveworker->sig_done.connect(sigc::mem_fun(*this, &FileSaver::files_saved)); saveworker->sig_progress.connect(sigc::mem_fun(*this, &FileSaver::on_progress)); saveworker->sig_waveform.connect(sigc::mem_fun(*this, &FileSaver::waveform_started)); saveworker->sig_waveform_progress.connect(sigc::mem_fun(*this, &FileSaver::on_waveform_progress)); // Show saving dialog savedialog->show_all(); saveprogressbar->set_fraction(0); // Change cursor to busy GdkDisplay* display; GdkCursor* cursor; GdkWindow* window; cursor = gdk_cursor_new(GDK_WATCH); display = gdk_display_get_default(); window = (GdkWindow*) filesaverdialog->get_window()->gobj(); gdk_window_set_cursor(window, cursor); gdk_display_sync(display); gdk_cursor_unref(cursor); } }
/** * gpm_backlight_dialog_show: * * Show the brightness popup, and place it nicely on the screen. **/ static void gpm_backlight_dialog_show (GpmBacklight *backlight) { int orig_w; int orig_h; int screen_w; int screen_h; int x; int y; int pointer_x; int pointer_y; GtkRequisition win_req; GdkScreen *pointer_screen; GdkRectangle geometry; int monitor; /* * get the window size * if the window hasn't been mapped, it doesn't necessarily * know its true size, yet, so we need to jump through hoops */ gtk_window_get_default_size (GTK_WINDOW (backlight->priv->popup), &orig_w, &orig_h); gtk_widget_size_request (backlight->priv->popup, &win_req); if (win_req.width > orig_w) { orig_w = win_req.width; } if (win_req.height > orig_h) { orig_h = win_req.height; } pointer_screen = NULL; gdk_display_get_pointer (gtk_widget_get_display (backlight->priv->popup), &pointer_screen, &pointer_x, &pointer_y, NULL); monitor = gdk_screen_get_monitor_at_point (pointer_screen, pointer_x, pointer_y); gdk_screen_get_monitor_geometry (pointer_screen, monitor, &geometry); screen_w = geometry.width; screen_h = geometry.height; x = ((screen_w - orig_w) / 2) + geometry.x; y = geometry.y + (screen_h / 2) + (screen_h / 2 - orig_h) / 2; gtk_window_move (GTK_WINDOW (backlight->priv->popup), x, y); gtk_widget_show (backlight->priv->popup); gdk_display_sync (gtk_widget_get_display (backlight->priv->popup)); }
static void force_quit_dialog_realize (GtkWidget *dialog, void *data) { WnckWindow *win = data; gdk_error_trap_push (); XSetTransientForHint (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_WINDOW_XID (gtk_widget_get_window (dialog)), wnck_window_get_xid (win)); gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop_ignored (); }
void Sidebar::setTmpDisabled(bool disabled) { XOJ_CHECK_TYPE(Sidebar); gtk_widget_set_sensitive(this->buttonCloseSidebar, !disabled); gtk_widget_set_sensitive(GTK_WIDGET(this->tbSelectPage), !disabled); for (GList * l = this->pages; l != NULL; l = l->next) { AbstractSidebarPage * p = (AbstractSidebarPage *) l->data; p->setTmpDisabled(disabled); } gdk_display_sync(gdk_display_get_default()); }
void Sidebar::setTmpDisabled(bool disabled) { XOJ_CHECK_TYPE(Sidebar); gtk_widget_set_sensitive(this->buttonCloseSidebar, !disabled); gtk_widget_set_sensitive(GTK_WIDGET(this->tbSelectPage), !disabled); for (AbstractSidebarPage* p : this->pages) { p->setTmpDisabled(disabled); } gdk_display_sync(gdk_display_get_default()); }
void gs_grab_release (GSGrab *grab) { gs_debug ("Releasing all grabs"); gs_grab_release_mouse (grab); gs_grab_release_keyboard (grab); /* FIXME: is it right to enable this ? */ xorg_lock_smasher_set_active (grab, TRUE); gdk_display_sync (gdk_display_get_default ()); gdk_flush (); }
void decor_update_switcher_property (decor_t *d) { long *data; Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); gint nQuad; decor_quad_t quads[N_QUADS_MAX]; unsigned int nOffset = 1; unsigned int frame_type = populate_frame_type (d); unsigned int frame_state = populate_frame_state (d); unsigned int frame_actions = populate_frame_actions (d); GtkStyleContext *context; GdkRGBA fg; long fgColor[4]; nQuad = decor_set_lSrStSbX_window_quads (quads, &d->frame->window_context_active, &d->border_layout, d->border_layout.top.x2 - d->border_layout.top.x1 - d->frame->window_context_active.extents.left - d->frame->window_context_active.extents.right - 32); data = decor_alloc_property (nOffset, WINDOW_DECORATION_TYPE_PIXMAP); decor_quads_to_property (data, nOffset - 1, cairo_xlib_surface_get_drawable (d->surface), &d->frame->win_extents, &d->frame->win_extents, &d->frame->win_extents, &d->frame->win_extents, 0, 0, quads, nQuad, frame_type, frame_state, frame_actions); context = gtk_widget_get_style_context (d->frame->style_window_rgba); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &fg); fgColor[0] = fg.red; fgColor[1] = fg.green; fgColor[2] = fg.blue; fgColor[3] = SWITCHER_ALPHA; gdk_error_trap_push (); XChangeProperty (xdisplay, d->prop_xid, win_decor_atom, XA_INTEGER, 32, PropModeReplace, (guchar *) data, PROP_HEADER_SIZE + BASE_PROP_SIZE + QUAD_PROP_SIZE * N_QUADS_MAX); XChangeProperty (xdisplay, d->prop_xid, switcher_fg_atom, XA_INTEGER, 32, PropModeReplace, (guchar *) fgColor, 4); gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop_ignored (); free (data); }
/* This function enables and disables the Ctrl-Alt-KP_star and Ctrl-Alt-KP_slash hot-keys, which (in XFree86 4.2) break any grabs and/or kill the grabbing client. That would effectively unlock the screen, so we don't like that. The Ctrl-Alt-KP_star and Ctrl-Alt-KP_slash hot-keys only exist if AllowDeactivateGrabs and/or AllowClosedownGrabs are turned on in XF86Config. I believe they are disabled by default. This does not affect any other keys (specifically Ctrl-Alt-BS or Ctrl-Alt-F1) but I wish it did. Maybe it will someday. */ static void xorg_lock_smasher_set_active (GSGrab *grab, gboolean active) { int status, event, error; #if GTK_CHECK_VERSION (3, 0, 0) if (!XF86MiscQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &event, &error)) #else if (!XF86MiscQueryExtension (GDK_DISPLAY (), &event, &error)) #endif { gs_debug ("No XFree86-Misc extension present"); return; } if (active) { gs_debug ("Enabling the x.org grab smasher"); } else { gs_debug ("Disabling the x.org grab smasher"); } gdk_error_trap_push (); #if GTK_CHECK_VERSION (3, 0, 0) status = XF86MiscSetGrabKeysState (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), active); #else status = XF86MiscSetGrabKeysState (GDK_DISPLAY (), active); #endif gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop (); if (active && status == MiscExtGrabStateAlready) { /* shut up, consider this success */ status = MiscExtGrabStateSuccess; } gs_debug ("XF86MiscSetGrabKeysState(%s) returned %s\n", active ? "on" : "off", (status == MiscExtGrabStateSuccess ? "MiscExtGrabStateSuccess" : status == MiscExtGrabStateLocked ? "MiscExtGrabStateLocked" : status == MiscExtGrabStateAlready ? "MiscExtGrabStateAlready" : "unknown value")); }
void set_cursor_busy(gboolean busy) { GdkCursor *cursor; if (busy) { cursor = gdk_cursor_new(GDK_WATCH); gdk_window_set_cursor(GTK_WIDGET(winMain)->window, cursor); gdk_window_set_cursor(GTK_WIDGET(canvas)->window, cursor); gdk_cursor_unref(cursor); } else { gdk_window_set_cursor(GTK_WIDGET(winMain)->window, NULL); update_cursor(); } gdk_display_sync(gdk_display_get_default()); }
char * xdevice_get_device_node (int deviceid) { Atom prop; Atom act_type; int act_format; unsigned long nitems, bytes_after; unsigned char *data; char *ret; gdk_display_sync (gdk_display_get_default ()); prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Device Node", False); if (!prop) return NULL; gdk_error_trap_push (); if (!XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceid, prop, 0, 1000, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) == Success) { gdk_error_trap_pop_ignored (); return NULL; } if (gdk_error_trap_pop ()) goto out; if (nitems == 0) goto out; if (act_type != XA_STRING) goto out; /* Unknown string format */ if (act_format != 8) goto out; ret = g_strdup ((char *) data); XFree (data); return ret; out: XFree (data); return NULL; }
static void gs_grab_nuke_focus (void) { Window focus = 0; int rev = 0; gs_debug ("Nuking focus"); gdk_error_trap_push (); XGetInputFocus (GDK_DISPLAY (), &focus, &rev); XSetInputFocus (GDK_DISPLAY (), None, RevertToNone, CurrentTime); gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop (); }
void GTKVideo::realize_cb(GtkWidget *widget, void *user_data) { GTKVideo *context = static_cast<GTKVideo *>(user_data); GdkWindow *window = gtk_widget_get_window(widget); if (!gdk_window_ensure_native(window)) g_debug("Couldn't create native window needed for GstXOverlay!"); gdk_threads_enter(); gdk_display_sync(context->display_); // gdk_error_trap_pop (); /* Retrieve window handler from GDK */ #if defined(GDK_WINDOWING_WIN32) context->window_handle_ = reinterpret_cast<guintptr>(GDK_WINDOW_HWND(window)); #elif defined(GDK_WINDOWING_QUARTZ) context->window_handle_ = gdk_quartz_window_get_nsview(window); #elif defined(GDK_WINDOWING_X11) context->window_handle_ = GDK_WINDOW_XID(window); #endif gdk_threads_leave(); std::unique_lock<std::mutex> lock(context->wait_window_mutex_); context->wait_window_cond_.notify_all(); }
static gboolean rb_vis_widget_expose_event (GtkWidget *widget, GdkEventExpose *event) { GdkWindow *window; RBVisWidget *rbvw = RB_VIS_WIDGET (widget); window = gtk_widget_get_window (widget); if (rbvw->window_xid != GDK_WINDOW_XWINDOW (window)) { rbvw->window_xid = GDK_WINDOW_XWINDOW (window); gdk_display_sync (gdk_drawable_get_display (GDK_DRAWABLE (window))); rb_debug ("got new window ID %lu", rbvw->window_xid); g_object_notify (G_OBJECT (rbvw), "window-xid"); } return TRUE; }
static void gs_grab_nuke_focus (void) { Window focus = 0; int rev = 0; gs_debug ("Nuking focus"); gdk_error_trap_push (); #if GTK_CHECK_VERSION (3, 0, 0) XGetInputFocus (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &focus, &rev); XSetInputFocus (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), None, RevertToNone, CurrentTime); #else XGetInputFocus (GDK_DISPLAY (), &focus, &rev); XSetInputFocus (GDK_DISPLAY (), None, RevertToNone, CurrentTime); #endif gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop (); }
/* ================================== FileSaver::files_saved Called once the files has been saved. ================================== */ void FileSaver::files_saved() { delete saveworker; saveworker = NULL; savedialog->hide_all(); if (waveformdialog->get_realized()) waveformdialog->hide_all(); // Set cursor back to normal GdkDisplay* display; GdkCursor* cursor; GdkWindow* window; cursor = gdk_cursor_new(GDK_LEFT_PTR); display = gdk_display_get_default(); window = (GdkWindow*) filesaverdialog->get_window()->gobj(); gdk_window_set_cursor(window, cursor); gdk_display_sync(display); gdk_cursor_unref(cursor); }
static VALUE rg_sync(VALUE self) { gdk_display_sync(_SELF(self)); return self; }
void decor_update_blur_property (decor_t *d, int width, int height, Region top_region, int top_offset, Region bottom_region, int bottom_offset, Region left_region, int left_offset, Region right_region, int right_offset) { Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); long *data = NULL; int size = 0; gint blur_type; g_object_get (settings, "blur", &blur_type, NULL); if (blur_type != BLUR_TYPE_ALL) { bottom_region = NULL; left_region = NULL; right_region = NULL; if (blur_type != BLUR_TYPE_TITLEBAR) top_region = NULL; } if (top_region) size += top_region->numRects; if (bottom_region) size += bottom_region->numRects; if (left_region) size += left_region->numRects; if (right_region) size += right_region->numRects; if (size) data = (long *) malloc (sizeof (long) * (2 + size * 6)); if (data) { decor_region_to_blur_property (data, 4, 0, width, height, top_region, top_offset, bottom_region, bottom_offset, left_region, left_offset, right_region, right_offset); gdk_error_trap_push (); XChangeProperty (xdisplay, d->prop_xid, win_blur_decor_atom, XA_INTEGER, 32, PropModeReplace, (guchar *) data, 2 + size * 6); gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop (); free (data); } else { gdk_error_trap_push (); XDeleteProperty (xdisplay, d->prop_xid, win_blur_decor_atom); gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop (); } }
static cairo_surface_t * snapshot_widget (GtkWidget *widget, SnapshotMode mode) { cairo_surface_t *surface; cairo_pattern_t *bg; GMainLoop *loop; cairo_t *cr; g_assert (gtk_widget_get_realized (widget)); surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget), CAIRO_CONTENT_COLOR, gtk_widget_get_allocated_width (widget), gtk_widget_get_allocated_height (widget)); loop = g_main_loop_new (NULL, FALSE); /* We wait until the widget is drawn for the first time. * We can not wait for a GtkWidget::draw event, because that might not * happen if the window is fully obscured by windowed child widgets. * Alternatively, we could wait for an expose event on widget's window. * Both of these are rather hairy, not sure what's best. */ gdk_event_handler_set (check_for_draw, loop, NULL); g_main_loop_run (loop); cr = cairo_create (surface); switch (mode) { case SNAPSHOT_WINDOW: { GdkWindow *window = gtk_widget_get_window (widget); if (gdk_window_get_window_type (window) == GDK_WINDOW_TOPLEVEL || gdk_window_get_window_type (window) == GDK_WINDOW_FOREIGN) { /* give the WM/server some time to sync. They need it. * Also, do use popups instead of toplevls in your tests * whenever you can. */ gdk_display_sync (gdk_window_get_display (window)); g_timeout_add (500, quit_when_idle, loop); g_main_loop_run (loop); } gdk_cairo_set_source_window (cr, window, 0, 0); cairo_paint (cr); } break; case SNAPSHOT_DRAW: bg = gdk_window_get_background_pattern (gtk_widget_get_window (widget)); if (bg) { cairo_set_source (cr, bg); cairo_paint (cr); } gtk_widget_draw (widget, cr); break; default: g_assert_not_reached(); break; } cairo_destroy (cr); g_main_loop_unref (loop); gtk_widget_destroy (widget); return surface; }
int main (int argc, char **argv) { GdkDisplay *display = NULL; int estatus; char *child_argv[] = { LIBEXECDIR "/cinnamon-session-check-accelerated-helper", NULL }; Window rootwin; glong is_accelerated; GError *error = NULL; gtk_init (NULL, NULL); display = gdk_display_get_default (); rootwin = gdk_x11_get_default_root_xwindow (); is_accelerated_atom = gdk_x11_get_xatom_by_name_for_display (display, "_CINNAMON_SESSION_ACCELERATED"); { Atom type; gint format; gulong nitems; gulong bytes_after; guchar *data; read: gdk_x11_display_error_trap_push (display); XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), rootwin, is_accelerated_atom, 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems, &bytes_after, &data); gdk_x11_display_error_trap_pop_ignored (display); if (type == XA_CARDINAL) { glong *is_accelerated_ptr = (glong*) data; if (*is_accelerated_ptr == ACCEL_CHECK_RUNNING) { /* Test in progress, wait */ if (wait_for_property_notify ()) goto read; /* else fall through and do the check ourselves */ } else { return (*is_accelerated_ptr == 0 ? 1 : 0); } } } /* We don't have the property or it's the wrong type. * Try to compute it now. */ /* First indicate that a test is in progress */ is_accelerated = ACCEL_CHECK_RUNNING; XChangeProperty (GDK_DISPLAY_XDISPLAY (display), rootwin, is_accelerated_atom, XA_CARDINAL, 32, PropModeReplace, (guchar *) &is_accelerated, 1); gdk_display_sync (display); estatus = 1; if (!g_spawn_sync (NULL, (char**)child_argv, NULL, 0, NULL, NULL, NULL, NULL, &estatus, &error)) { is_accelerated = FALSE; g_printerr ("cinnamon-session-check-accelerated: Failed to run helper: %s\n", error->message); g_clear_error (&error); } else { is_accelerated = (estatus == 0); if (!is_accelerated) g_printerr ("cinnamon-session-check-accelerated: Helper exited with code %d\n", estatus); } XChangeProperty (GDK_DISPLAY_XDISPLAY (display), rootwin, is_accelerated_atom, XA_CARDINAL, 32, PropModeReplace, (guchar *) &is_accelerated, 1); gdk_display_sync (display); return is_accelerated ? 0 : 1; }
int xdevice_get_last_tool_id (int deviceid) { Atom prop; Atom act_type; int act_format; unsigned long nitems, bytes_after; unsigned char *data; int id; id = -1; gdk_display_sync (gdk_display_get_default ()); prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), WACOM_SERIAL_IDS_PROP, False); if (!prop) return -1; data = NULL; gdk_error_trap_push (); if (XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceid, prop, 0, 1000, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) != Success) { gdk_error_trap_pop_ignored (); goto out; } if (gdk_error_trap_pop ()) goto out; if (nitems != 4 && nitems != 5) goto out; if (act_type != XA_INTEGER) goto out; if (act_format != TOOL_ID_FORMAT_SIZE) goto out; /* item 0 = tablet ID * item 1 = old device serial number (== last tool in proximity) * item 2 = old hardware serial number (including tool ID) * item 3 = current serial number (0 if no tool in proximity) * item 4 = current tool ID (since Feb 2012) * * Get the current tool ID first, if available, then the old one */ id = 0x0; if (nitems == 5) id = get_id_for_index (data, 4); if (id == 0x0) id = get_id_for_index (data, 2); /* That means that no tool was set down yet */ if (id == STYLUS_DEVICE_ID || id == ERASER_DEVICE_ID) id = 0x0; out: if (data != NULL) XFree (data); return id; }
Client * newclient(void) { Client *c; WebKitWebSettings *settings; gchar *uri; if(!(c = calloc(1, sizeof(Client)))) die("Cannot malloc!\n"); /* Window */ if(embed) { c->win = gtk_plug_new(embed); } else { c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "surf"); } gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600); g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c); g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c); /* VBox */ c->vbox = gtk_vbox_new(FALSE, 0); /* scrolled window */ c->scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll), GTK_POLICY_NEVER, GTK_POLICY_NEVER); /* webview */ c->view = WEBKIT_WEB_VIEW(webkit_web_view_new()); g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c); g_signal_connect(G_OBJECT(c->view), "load-progress-changed", G_CALLBACK(progresschange), c); g_signal_connect(G_OBJECT(c->view), "load-finished", G_CALLBACK(loadfinished), c); g_signal_connect(G_OBJECT(c->view), "load-committed", G_CALLBACK(loadcommit), c); g_signal_connect(G_OBJECT(c->view), "load-started", G_CALLBACK(loadstart), c); g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c); g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(newwindow), c); g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c); g_signal_connect(G_OBJECT(c->view), "window-object-cleared", G_CALLBACK(windowobjectcleared), c); g_signal_connect_after(session, "request-started", G_CALLBACK(request), c); /* urlbar */ c->urlbar = gtk_entry_new(); gtk_entry_set_has_frame(GTK_ENTRY(c->urlbar), FALSE); g_signal_connect(G_OBJECT(c->urlbar), "focus-out-event", G_CALLBACK(unfocusbar), c); /* searchbar */ c->searchbar = gtk_entry_new(); gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE); g_signal_connect(G_OBJECT(c->searchbar), "focus-out-event", G_CALLBACK(unfocusbar), c); /* indicator */ c->indicator = gtk_drawing_area_new(); gtk_widget_set_size_request(c->indicator, 0, 2); g_signal_connect (G_OBJECT (c->indicator), "expose_event", G_CALLBACK (exposeindicator), c); /* Arranging */ gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view)); gtk_container_add(GTK_CONTAINER(c->win), c->vbox); gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll); gtk_container_add(GTK_CONTAINER(c->vbox), c->searchbar); gtk_container_add(GTK_CONTAINER(c->vbox), c->urlbar); gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator); /* Setup */ gtk_box_set_child_packing(GTK_BOX(c->vbox), c->urlbar, FALSE, FALSE, 0, GTK_PACK_START); gtk_box_set_child_packing(GTK_BOX(c->vbox), c->searchbar, FALSE, FALSE, 0, GTK_PACK_START); gtk_box_set_child_packing(GTK_BOX(c->vbox), c->indicator, FALSE, FALSE, 0, GTK_PACK_START); gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START); gtk_widget_grab_focus(GTK_WIDGET(c->view)); gtk_widget_hide_all(c->searchbar); gtk_widget_hide_all(c->urlbar); gtk_widget_show(c->vbox); gtk_widget_show(c->indicator); gtk_widget_show(c->scroll); gtk_widget_show(GTK_WIDGET(c->view)); gtk_widget_show(c->win); gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK); gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c); webkit_web_view_set_full_content_zoom(c->view, TRUE); settings = webkit_web_view_get_settings(c->view); g_object_set(G_OBJECT(settings), "user-agent", "surf", NULL); uri = g_strconcat("file://", stylefile, NULL); g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); g_free(uri); c->download = NULL; c->title = NULL; c->next = clients; clients = c; if(showxid) { gdk_display_sync(gtk_widget_get_display(c->win)); printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window)); fflush(NULL); } return c; }
int main(int argc, char *argv[]) { Arg arg; Client *c; GdkGeometry hints = { 1, 1 }; memset(&arg, 0, sizeof(arg)); /* command line args */ ARGBEGIN { case 'e': embed = strtol(EARGF(usage()), NULL, 0); break; case 'v': die("turf-"VERSION", ©2014 turf engineers, " "see LICENSE for details\n"); case 'x': showxid = TRUE; break; default: usage(); } ARGEND; if(argc > 0) arg.v = argv[0]; sigchld(0); gtk_init(NULL, NULL); gtk_gl_init(NULL, NULL); dpy = GDK_DISPLAY(); /* atoms */ atoms[AtomFind] = XInternAtom(dpy, "_TURF_FIND", False); atoms[AtomGo] = XInternAtom(dpy, "_TURF_GO", False); atoms[AtomUri] = XInternAtom(dpy, "_TURF_URI", False); if(!(c = calloc(1, sizeof(Client)))) die("Cannot malloc!\n"); /* WIndow */ if(embed) { c->win = gtk_plug_new(embed); } else { c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_wmclass(GTK_WINDOW(c->win), "turf", "Turf"); gtk_window_set_role(GTK_WINDOW(c->win), "Turf"); } gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600); g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c); c->vbox = gtk_vbox_new(FALSE, 0); /* cef init */ cef_settings_t *settings; if(!(settings = malloc(sizeof(cef_settings_t)))) die("Cannot malloc\n"); cef_initialize(NULL, settings, NULL); /* cef set as child (vbox) */ gtk_container_add(GTK_CONTAINER(c->win), c->vbox); gtk_widget_show_all(GTK_WIDGET(c->win)); gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints, GDK_HINT_MIN_SIZE); gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK); /* process X events for window - aka AtomFind/AtomGo * gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c); * setatom(c, AtomFind, ""); * setatom(c, AtomUri, "about:blank"); */ c->title = NULL; c->next = clients; clients = c; if(showxid) { gdk_display_sync(gtk_widget_get_display(c->win)); printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window)); fflush(NULL); if (fclose(stdout) != 0) { die("Error closing stdout"); } } if(arg.v) loaduri(clients, &arg); gtk_main(); cleanup(); return EXIT_SUCCESS; }
/* * update_event_windows * * Returns: void * Description: creates small "event windows" for the buttons specified to be * on the titlebar by wnck. Note here that for the pixmap mode we create actual * X windows but in the reparenting mode this is not possible so we create event * capture boxes on the window instead. The geometry of the decoration is retrieved * with window_get_client_window_geometry and adjusted for shade. Also we * need to query the theme for what window positions are appropriate here. * * This function works on the buttons and also the small event regions that we need * in order to toggle certain actions on the window decoration (eg resize, move) * * So your window decoration might look something like this (not to scale): * * ----------------------------------------------------------- * | rtl | rt | rtr | * | --- |---------------------------------------------| --- | * | | [i][s][m] mv [_][M][X] | | * | |---------------------------------------------| | * | | | | * | rl | window contents | rr | * | | | | * | | | | * | --- |---------------------------------------------| --- | * | rbl | rb | rbr | * ----------------------------------------------------------- * * Where: * - rtl = resize top left * - rtr = resize top right * - rbl = resize bottom left * - rbr = resize bottom right * - rt = resize top * - rb = resize bottom * - rl = resize left * - rr = resize right * - mv = "grab move" area (eg titlebar) * - i = icon * - s = shade * - m = menu * - _ = minimize * - M = maximize * - X = close * * For the reparenting mode we use button_windows[i].pos and for the pixmap mode * we use buttons_windows[i].window * */ void update_event_windows (WnckWindow *win) { Display *xdisplay; decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); gint x0, y0, width, height, x, y, w, h; gint i, j, k, l; gint actions = d->actions; xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); /* Get the geometry of the client */ wnck_window_get_client_window_geometry (win, &x0, &y0, &width, &height); /* Shaded windows have no height - also skip some event windows */ if (d->state & WNCK_WINDOW_STATE_SHADED) { height = 0; k = l = 1; } else { k = 0; l = 2; } gdk_error_trap_push (); /* [rtl, ru, rtr], [rl, mv, rr], [rbl, rb, rbr] */ for (i = 0; i < 3; ++i) { static guint event_window_actions[3][3] = { { WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_RESIZE }, { WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_MOVE, WNCK_WINDOW_ACTION_RESIZE }, { WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_RESIZE } }; for (j = 0; j < 3; ++j) { w = 0; h = 0; if (actions & event_window_actions[i][j] && i >= k && i <= l) (*theme_get_event_window_position) (d, i, j, width, height, &x, &y, &w, &h); /* Reparenting mode - create boxes which we monitor motionnotify on */ if (d->frame_window) { BoxPtr box = &d->event_windows[i][j].pos; box->x1 = x; box->x2 = x + w; box->y1 = y; box->y2 = y + h; } /* Pixmap mode with window geometry - create small event windows */ else if (!d->frame_window && w != 0 && h != 0) { XMapWindow (xdisplay, d->event_windows[i][j].window); XMoveResizeWindow (xdisplay, d->event_windows[i][j].window, x, y, w, h); } /* No parent and no geometry - unmap all event windows */ else if (!d->frame_window) { XUnmapWindow (xdisplay, d->event_windows[i][j].window); } } } /* no button event windows if width is less than minimum width */ if (width < ICON_SPACE + d->button_width) actions = 0; /* Above, stick, unshade and unstick are only available in wnck => 2.18.1 */ for (i = 0; i < BUTTON_NUM; ++i) { static guint button_actions[BUTTON_NUM] = { WNCK_WINDOW_ACTION_CLOSE, WNCK_WINDOW_ACTION_MAXIMIZE, WNCK_WINDOW_ACTION_MINIMIZE, 0, WNCK_WINDOW_ACTION_SHADE, WNCK_WINDOW_ACTION_ABOVE, WNCK_WINDOW_ACTION_STICK, WNCK_WINDOW_ACTION_UNSHADE, WNCK_WINDOW_ACTION_ABOVE, WNCK_WINDOW_ACTION_UNSTICK }; /* Reparenting mode - if a box was set and we no longer need it reset its geometry */ if (d->frame_window && button_actions[i] && !(actions & button_actions[i])) { memset (&d->button_windows[i].pos, 0, sizeof (Box)); } /* Pixmap mode - if a box was set and we no longer need it unmap its window */ else if (!d->frame_window && button_actions[i] && !(actions & button_actions[i])) { XUnmapWindow (xdisplay, d->button_windows[i].window); continue; } /* Reparenting mode - if there is a button position for this * button then set the geometry */ if (d->frame_window && (*theme_get_button_position) (d, i, width, height, &x, &y, &w, &h)) { BoxPtr box = &d->button_windows[i].pos; box->x1 = x; box->y1 = y; box->x2 = x + w; box->y2 = y + h; } /* Pixmap mode - if there is a button position for this button then map the window * and resize it to this position */ else if (!d->frame_window && (*theme_get_button_position) (d, i, width, height, &x, &y, &w, &h)) { Window x11_win = d->button_windows[i].window; XMapWindow (xdisplay, x11_win); XMoveResizeWindow (xdisplay, x11_win, x, y, w, h); } else if (!d->frame_window) { XUnmapWindow (xdisplay, d->button_windows[i].window); } } gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop_ignored (); }
Client * newclient(void) { int i; Client *c; WebKitWebSettings *settings; GdkGeometry hints = { 1, 1 }; char *uri, *ua; if(!(c = calloc(1, sizeof(Client)))) die("Cannot malloc!\n"); /* Window */ if(embed) { c->win = gtk_plug_new(embed); } else { c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* TA: 20091214: Despite what the GNOME docs say, the ICCCM * is always correct, so we should still call this function. * But when doing so, we *must* differentiate between a * WM_CLASS and a resource on the window. By convention, the * window class (WM_CLASS) is capped, while the resource is in * lowercase. Both these values come as a pair. */ gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "surf"); /* TA: 20091214: And set the role here as well -- so that * sessions can pick this up. */ gtk_window_set_role(GTK_WINDOW(c->win), "Surf"); } gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600); g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c); g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c); g_signal_connect(G_OBJECT(c->win), "size-allocate", G_CALLBACK(resize), c); if(!(c->items = calloc(1, sizeof(GtkWidget *) * LENGTH(items)))) die("Cannot malloc!\n"); /* contextmenu */ for(i = 0; i < LENGTH(items); i++) { c->items[i] = gtk_menu_item_new_with_label(items[i].label); g_signal_connect(G_OBJECT(c->items[i]), "activate", G_CALLBACK(itemclick), c); } /* VBox */ c->vbox = gtk_vbox_new(FALSE, 0); /* Scrolled Window */ c->scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll), GTK_POLICY_NEVER, GTK_POLICY_NEVER); /* Webview */ c->view = WEBKIT_WEB_VIEW(webkit_web_view_new()); g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c); g_signal_connect(G_OBJECT(c->view), "load-progress-changed", G_CALLBACK(progresschange), c); g_signal_connect(G_OBJECT(c->view), "load-committed", G_CALLBACK(loadcommit), c); g_signal_connect(G_OBJECT(c->view), "load-started", G_CALLBACK(loadstart), c); g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c); g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(createwindow), c); g_signal_connect(G_OBJECT(c->view), "new-window-policy-decision-requested", G_CALLBACK(decidewindow), c); g_signal_connect(G_OBJECT(c->view), "mime-type-policy-decision-requested", G_CALLBACK(decidedownload), c); g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c); g_signal_connect(G_OBJECT(c->view), "window-object-cleared", G_CALLBACK(windowobjectcleared), c); g_signal_connect(G_OBJECT(c->view), "populate-popup", G_CALLBACK(context), c); /* Indicator */ c->indicator = gtk_drawing_area_new(); gtk_widget_set_size_request(c->indicator, 0, 2); g_signal_connect (G_OBJECT (c->indicator), "expose_event", G_CALLBACK (exposeindicator), c); /* Arranging */ gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view)); gtk_container_add(GTK_CONTAINER(c->win), c->vbox); gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll); gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator); /* Setup */ gtk_box_set_child_packing(GTK_BOX(c->vbox), c->indicator, FALSE, FALSE, 0, GTK_PACK_START); gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START); gtk_widget_grab_focus(GTK_WIDGET(c->view)); gtk_widget_show(c->vbox); gtk_widget_show(c->indicator); gtk_widget_show(c->scroll); gtk_widget_show(GTK_WIDGET(c->view)); gtk_widget_show(c->win); gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints, GDK_HINT_MIN_SIZE); gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK); gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c); webkit_web_view_set_full_content_zoom(c->view, TRUE); settings = webkit_web_view_get_settings(c->view); if(!(ua = getenv("SURF_USERAGENT"))) ua = useragent; g_object_set(G_OBJECT(settings), "user-agent", ua, NULL); uri = g_strconcat("file://", stylefile, NULL); g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); g_free(uri); setatom(c, findprop, ""); c->download = NULL; c->title = NULL; c->next = clients; clients = c; if(showxid) { gdk_display_sync(gtk_widget_get_display(c->win)); printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window)); fflush(NULL); } return c; }