/* Copied from nautilus */ static gchar * get_direct_save_filename (GdkDragContext *context) { guchar *prop_text; gint prop_len; if (!gdk_property_get (gdk_drag_context_get_source_window (context), gdk_atom_intern ("XdndDirectSave0", FALSE), gdk_atom_intern ("text/plain", FALSE), 0, 1024, FALSE, NULL, NULL, &prop_len, &prop_text) && prop_text != NULL) { return NULL; } /* Zero-terminate the string */ prop_text = g_realloc (prop_text, prop_len + 1); prop_text[prop_len] = '\0'; /* Verify that the file name provided by the source is valid */ if (*prop_text == '\0' || strchr ((const gchar *) prop_text, G_DIR_SEPARATOR) != NULL) { gedit_debug_message (DEBUG_UTILS, "Invalid filename provided by XDS drag site"); g_free (prop_text); return NULL; } return (gchar *)prop_text; }
gint gtksharp_get_gdk_net_current_desktop (void) { GdkAtom actual_property_type; int actual_format; int actual_length; long *data = NULL; gint current_desktop; if (!gdk_property_get ( gdk_screen_get_root_window (gdk_screen_get_default ()), gdk_atom_intern ("_NET_CURRENT_DESKTOP", FALSE), gdk_atom_intern ("CARDINAL", FALSE), 0, G_MAXLONG, FALSE, &actual_property_type, &actual_format, &actual_length, (guchar **) &data)) { gchar *actual_property_type_name; g_critical ("Unable to get _NET_CURRENT_DESKTOP"); actual_property_type_name = gdk_atom_name (actual_property_type); if (actual_property_type_name) { g_message ("actual_property_type: %s", actual_property_type_name); g_free (actual_property_type_name); } return -1; } current_desktop = (gint) data[0]; g_free (data); return current_desktop; }
gint tomboy_window_get_workspace (GtkWindow *window) { #ifndef GDK_WINDOWING_X11 return -1; #else GdkWindow *gdkwin = gtk_widget_get_window(GTK_WIDGET (window)); GdkAtom wm_desktop = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE); GdkAtom out_type; gint out_format, out_length; gulong *out_val; int workspace; if (!gdk_property_get (gdkwin, wm_desktop, _GDK_MAKE_ATOM (XA_CARDINAL), 0, G_MAXLONG, FALSE, &out_type, &out_format, &out_length, (guchar **) &out_val)) return -1; workspace = *out_val; g_free (out_val); return workspace; #endif }
static PyObject * PyGdkWindow_PropertyGet(PyGdkWindow_Object *self, PyObject *args) { PyObject *py_property, py_type = NULL; gint pdelete = FALSE; GdkAtom atype, property, type; gint aformat, alength; guchar *data; if (!PyArg_ParseTuple(args, "O|Oi:GdkWindow.property_get", &py_property, &py_type, &pdelete)) { return NULL; } property = pygdk_atom_from_pyobject(py_property); if (Pyerr_Occurred()) return NULL; type = pygdk_atom_from_pyobject(py_type); if (Pyerr_Occurred()) return NULL; if (gdk_property_get(self->obj, property, type, 0, G_MAXLONG, pdelete, &atype, &aformat, &alength, &data)) { /* success */ PyObject *pdata = NULL; gint i; guint16 *data16; guint32 *data32; switch (aformat) { case 8: if ((pdata = PyString_FromStringAndSize(data, alength)) == NULL) return NULL; break; case 16: data16 = (guint16 *)data; if ((pdata = PyTuple_New(alength)) == NULL) return NULL; for (i = 0; i < alength; i++) PyTuple_SetItem(pdata, i, PyInt_FromLong(data16[i])); break; case 32: data32 = (guint32 *)data; if ((pdata = PyTuple_New(alength)) == NULL) return NULL; for (i = 0; i < alength; i++) PyTuple_SetItem(pdata, i, PyInt_FromLong(data32[i])); break; default: g_warning("got a property format != 8, 16 or 32"); g_assert_not_reached(); } g_free(data); return Py_BuildValue("(NiN)", PyGdkAtom_New(atype), aformat, pdata); } else { Py_INCREF(Py_None); return Py_None; } }
CAMLprim value ml_gdk_property_get (value window, value property, value length, value pdelete) { #if defined(_WIN32) || defined(__CYGWIN__) || defined(HAS_GTKQUARTZ) return Val_unit; /* not supported */ #else GdkAtom atype; int aformat, alength; guchar *data; int nitems; int ok = gdk_property_get (GdkWindow_val(window), GdkAtom_val(property), AnyPropertyType, 0, Long_val(length), Bool_val(pdelete), &atype, &aformat, &alength, &data); if (ok) { CAMLparam0(); CAMLlocal3(mltype, mldata, pair); switch (aformat) { case 16: nitems = alength / sizeof(short); break; case 32: nitems = alength / sizeof(long); break; default: nitems = alength; } mldata = copy_xdata (aformat, data, nitems); mltype = Val_GdkAtom (atype); pair = alloc_small(2,0); Field(pair,0) = mltype; Field(pair,1) = mldata; CAMLreturn(ml_some (pair)); } return Val_unit; #endif }
static char * get_direct_save_filename (GdkDragContext *context) { guchar *prop_text; gint prop_len; if (!gdk_property_get (gdk_drag_context_get_source_window (context), gdk_atom_intern (NEMO_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE), gdk_atom_intern ("text/plain", FALSE), 0, 1024, FALSE, NULL, NULL, &prop_len, &prop_text)) { return NULL; } /* Zero-terminate the string */ prop_text = g_realloc (prop_text, prop_len + 1); prop_text[prop_len] = '\0'; /* Verify that the file name provided by the source is valid */ if (*prop_text == '\0' || strchr ((const gchar *) prop_text, G_DIR_SEPARATOR) != NULL) { DEBUG ("Invalid filename provided by XDS drag site"); g_free (prop_text); return NULL; } return prop_text; }
static gboolean get_desktop_window (Window *window) { Window *desktop_window; GdkWindow *root_window; GdkAtom type_returned; int format_returned; int length_returned; root_window = gdk_screen_get_root_window ( gdk_screen_get_default ()); if (gdk_property_get (root_window, gdk_atom_intern ("CAJA_DESKTOP_WINDOW_ID", FALSE), gdk_x11_xatom_to_atom (XA_WINDOW), 0, 4, FALSE, &type_returned, &format_returned, &length_returned, (guchar**) &desktop_window)) { *window = *desktop_window; g_free (desktop_window); return TRUE; } else { *window = 0; return FALSE; } }
guint gtksharp_get_gdk_net_active_window (void) { GdkAtom actual_property_type; int actual_format; int actual_length; long *data = NULL; guint windowID = 0; if (!gdk_property_get ( gdk_screen_get_root_window (gdk_screen_get_default ()), gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE), gdk_atom_intern ("WINDOW", FALSE), 0, G_MAXLONG, FALSE, &actual_property_type, &actual_format, &actual_length, (guchar **) &data)) { gchar *actualPropertyTypeName; g_critical ("Unable to get _NET_ACTIVE_WINDOW"); actualPropertyTypeName = gdk_atom_name (actual_property_type); if (actualPropertyTypeName) { g_message ("actual_property_type: %s", actualPropertyTypeName); g_free(actualPropertyTypeName); } return -1; } windowID = (gint) data [0]; g_free (data); return windowID; }
static gboolean gth_file_list_drag_drop (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) { GthBrowser *browser = user_data; int filename_len; char *filename; g_signal_stop_emission_by_name (widget, "drag-drop"); if (gdk_property_get (gdk_drag_context_get_source_window (context), XDND_ACTION_DIRECT_SAVE_ATOM, TEXT_PLAIN_ATOM, 0, 1024, FALSE, NULL, NULL, &filename_len, (guchar **) &filename) && GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser))) { GFile *file; char *uri; filename = g_realloc (filename, filename_len + 1); filename[filename_len] = '\0'; file = _g_file_append_path (gth_browser_get_location (browser), filename); uri = g_file_get_uri (file); gdk_property_change (gdk_drag_context_get_source_window (context), XDND_ACTION_DIRECT_SAVE_ATOM, TEXT_PLAIN_ATOM, 8, GDK_PROP_MODE_REPLACE, (const guchar *) uri, strlen (uri)); g_free (uri); g_object_unref (file); g_free (filename); gtk_drag_get_data (widget, context, XDND_ACTION_DIRECT_SAVE_ATOM, time); } else gtk_drag_get_data (widget, context, URI_LIST_ATOM, time); return TRUE; }
void tomboy_window_move_to_current_workspace (GtkWindow *window) { #ifndef GDK_WINDOWING_X11 return; #else GdkWindow *gdkwin = gtk_widget_get_window(GTK_WIDGET (window)); GdkWindow *rootwin = gdk_screen_get_root_window (gdk_window_get_screen (gdkwin)); GdkAtom current_desktop = gdk_atom_intern ("_NET_CURRENT_DESKTOP", FALSE); GdkAtom wm_desktop = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE); GdkAtom out_type; gint out_format, out_length; gulong *out_val; int workspace; XEvent xev; if (!gdk_property_get (rootwin, current_desktop, _GDK_MAKE_ATOM (XA_CARDINAL), 0, G_MAXLONG, FALSE, &out_type, &out_format, &out_length, (guchar **) &out_val)) return; workspace = *out_val; g_free (out_val); TRACE (g_print ("Setting _NET_WM_DESKTOP to: %d\n", workspace)); xev.xclient.type = ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.display = GDK_WINDOW_XDISPLAY (gdkwin); xev.xclient.window = GDK_WINDOW_XID (gdkwin); xev.xclient.message_type = gdk_x11_atom_to_xatom_for_display( gdk_window_get_display (gdkwin), wm_desktop); xev.xclient.format = 32; xev.xclient.data.l[0] = workspace; xev.xclient.data.l[1] = 0; xev.xclient.data.l[2] = 0; XSendEvent (GDK_WINDOW_XDISPLAY (rootwin), GDK_WINDOW_XID (rootwin), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); #endif }
GList * gtksharp_get_gdk_net_workarea (void) { GdkAtom actual_property_type; int actual_format; int actual_length; long *data = NULL; int i = 0; GList *list = NULL; if (!gdk_property_get ( gdk_screen_get_root_window (gdk_screen_get_default ()), gdk_atom_intern ("_NET_WORKAREA", FALSE), gdk_atom_intern ("CARDINAL", FALSE), 0, G_MAXLONG, FALSE, &actual_property_type, &actual_format, &actual_length, (guchar **) &data)) { gchar *actualPropertyTypeName; g_critical ("Unable to get _NET_WORKAREA"); actualPropertyTypeName = gdk_atom_name (actual_property_type); if (actualPropertyTypeName) { g_message ("actual_property_type: %s", actualPropertyTypeName); g_free(actualPropertyTypeName); } return FALSE; } for (i = 0; i < actual_length / sizeof (long); i += 4) { GdkRectangle *rectangle = g_malloc(sizeof (GdkRectangle)); rectangle->x = (int) data [i]; rectangle->y = (int) data [i + 1]; rectangle->width = (int) data [i + 2]; rectangle->height = (int) data [i + 3]; list = g_list_append (list, rectangle); } if (data != NULL) g_free(data); return list; }
char* matenu_settings_get_by_atom (MatenuSettings* self, GdkAtom atom) { char* result = NULL; char* context; GdkAtom actual_type; GdkAtom type; gint actual_format = 0; gint actual_length = 0; char* _tmp1_; char* _tmp0_ = NULL; g_return_val_if_fail (self != NULL, NULL); context = NULL; type = gdk_atom_intern ("STRING", FALSE); gdk_property_get (self->priv->_window, atom, type, (gulong) 0, (gulong) G_MAXLONG, FALSE, &actual_type, &actual_format, &actual_length, &_tmp0_); context = (_tmp1_ = _tmp0_, _g_free0 (context), _tmp1_); result = context; return result; }
guint * gtksharp_get_gdk_net_client_list (int *count) { GdkAtom actual_property_type; int actual_format; int actual_length; long *data = NULL; guint * list = NULL; int i; if (!gdk_property_get ( gdk_screen_get_root_window (gdk_screen_get_default ()), gdk_atom_intern ("_NET_CLIENT_LIST", FALSE), gdk_atom_intern ("WINDOW", FALSE), 0, G_MAXLONG, FALSE, &actual_property_type, &actual_format, &actual_length, (guchar **) &data)) { gchar *actual_property_type_name; g_critical ("Unable to get _NET_CLIENT_LIST"); actual_property_type_name = gdk_atom_name (actual_property_type); if (actual_property_type_name) { g_message ("actual_property_type: %s", actual_property_type_name); g_free (actual_property_type_name); } return NULL; } *count = actual_length / sizeof (long); list = g_malloc (*count * sizeof (guint)); /* Put all of the windows into a GList to return */ for (i = 0; i < *count; i ++) { list [i] = data [i]; g_message ("WinID: %d", list [i]); } g_free (data); return list; }
static int get_initial_workspace (void) { int ret = -1; GdkWindow *window; guchar *data = NULL; GdkAtom atom; GdkAtom cardinal_atom; window = gdk_get_default_root_window(); atom = gdk_atom_intern_static_string ("_NET_CURRENT_DESKTOP"); cardinal_atom = gdk_atom_intern_static_string ("CARDINAL"); if (gdk_property_get (window, atom, cardinal_atom, 0, 8, FALSE, NULL, NULL, NULL, &data)) { ret = *(int *)data; g_free (data); } return ret; }
static GtkWindowState getWindowState (GtkWidget *window) { GdkWindow *gdkWindow = window->window; GdkAtom actualType; gint actualFormat, actualLength; glong *data; GtkWindowState state = WITHDRAWN_STATE; if (window == NULL) return WITHDRAWN_STATE; if (gdk_property_get (gdkWindow, WM_STATE, WM_STATE, 0, 1, FALSE, &actualType, &actualFormat, &actualLength, (guchar **)&data)) { state = (GtkWindowState)*data; g_free (data); } return state; }
GList* gdk_get_net_supported () { GdkAtom actual_property_type; int actual_format; int actual_length; long *data = NULL; GList *list = NULL; unsigned short i; if (!gdk_property_get(gdk_screen_get_root_window(gdk_screen_get_default()), gdk_atom_intern("_NET_SUPPORTED", FALSE), gdk_atom_intern("ATOM", FALSE), 0, G_MAXLONG, FALSE, &actual_property_type, &actual_format, &actual_length, (guchar**)&data)) { gchar *actual_property_type_name; LOG_ERR("unable to get _NET_SUPPORTED"); actual_property_type_name = gdk_atom_name(actual_property_type); if (actual_property_type_name) { LOG_INFO("actual_property_type: %s", actual_property_type_name); g_free(actual_property_type_name); } return NULL; } /* Put all of the GdkAtoms into a GList to return */ for (i = 0; i < actual_length / sizeof(long); i++) { list = g_list_append(list, (GdkAtom)data[i]); } g_free(data); return list; }
/* The following three functions taken from bugzilla * (http://bugzilla.gnome.org/attachment.cgi?id=49362&action=view) * Author: Christian Neumair * Copyright: 2005 Free Software Foundation, Inc * License: GPL */ static char * xds_get_atom_value (GdkDragContext *context) { GdkWindow *source_window; char *ret; gint len; g_return_val_if_fail (context != NULL, NULL); source_window = gdk_drag_context_get_source_window (context); g_return_val_if_fail (source_window != NULL, NULL); if (gdk_property_get (source_window, XDS_ATOM, TEXT_ATOM, 0, MAX_XDS_ATOM_VAL_LEN, FALSE, NULL, NULL, &len, (unsigned char **) &ret)) { ret[len]='\0'; return ret; } return NULL; }
gchar *xfce_background_get_current_image() { GdkAtom atom; gint fmt; gint len; /*guchar buf[2049];*/ guchar *buf; buf = NULL; if (gdk_property_get( gdk_screen_get_root_window( gdk_display_get_default_screen(gdk_display_get_default()) ), gdk_atom_intern("XFDESKTOP_IMAGE_FILE_0", FALSE), gdk_x11_xatom_to_atom(XA_STRING), 0, 2048, 0, &atom, &fmt, &len, &buf) && fmt == 8) { buf[len] = 0; return buf; } return NULL; }
// Get the display ICC profile of the monitor associated with the widget. // For X display, uses the ICC profile specifications version 0.2 from // http://burtonini.com/blog/computers/xicc // Based on code from Gimp's modules/cdisplay_lcms.c void dt_ctl_set_display_profile() { if(!dt_control_running()) return; // make sure that no one gets a broken profile // FIXME: benchmark if the try is really needed when moving/resizing the window. Maybe we can just lock it and block if(pthread_rwlock_trywrlock(&darktable.control->xprofile_lock)) return; // we are already updating the profile. Or someone is reading right now. Too bad we can't distinguish that. Whatever ... GtkWidget *widget = dt_ui_center(darktable.gui->ui); guint8 *buffer = NULL; gint buffer_size = 0; gchar *profile_source = NULL; #if defined GDK_WINDOWING_X11 // we will use the xatom no matter what configured when compiled without colord gboolean use_xatom = TRUE; #if defined USE_COLORDGTK gboolean use_colord = TRUE; gchar *display_profile_source = dt_conf_get_string("ui_last/display_profile_source"); if(display_profile_source) { if(!strcmp(display_profile_source, "xatom")) use_colord = FALSE; else if(!strcmp(display_profile_source, "colord")) use_xatom = FALSE; g_free(display_profile_source); } #endif /* let's have a look at the xatom, just in case ... */ if(use_xatom) { GdkScreen *screen = gtk_widget_get_screen(widget); if ( screen==NULL ) screen = gdk_screen_get_default(); int monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window(widget)); char *atom_name; if (monitor > 0) atom_name = g_strdup_printf("_ICC_PROFILE_%d", monitor); else atom_name = g_strdup("_ICC_PROFILE"); profile_source = g_strdup_printf("xatom %s", atom_name); GdkAtom type = GDK_NONE; gint format = 0; gdk_property_get(gdk_screen_get_root_window(screen), gdk_atom_intern(atom_name, FALSE), GDK_NONE, 0, 64 * 1024 * 1024, FALSE, &type, &format, &buffer_size, &buffer); g_free(atom_name); } #ifdef USE_COLORDGTK /* also try to get the profile from colord. this will set the value asynchronously! */ if(use_colord) { CdWindow *window = cd_window_new(); GtkWidget *center_widget = dt_ui_center(darktable.gui->ui); cd_window_get_profile(window, center_widget, NULL, dt_ctl_get_display_profile_colord_callback, NULL); } #endif #elif defined GDK_WINDOWING_QUARTZ GdkScreen *screen = gtk_widget_get_screen(widget); if ( screen==NULL ) screen = gdk_screen_get_default(); int monitor = gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(widget)); CGDirectDisplayID ids[monitor + 1]; uint32_t total_ids; CMProfileRef prof = NULL; if(CGGetOnlineDisplayList(monitor + 1, &ids[0], &total_ids) == kCGErrorSuccess && total_ids == monitor + 1) CMGetProfileByAVID(ids[monitor], &prof); if ( prof!=NULL ) { CFDataRef data; data = CMProfileCopyICCData(NULL, prof); CMCloseProfile(prof); UInt8 *tmp_buffer = (UInt8 *) g_malloc(CFDataGetLength(data)); CFDataGetBytes(data, CFRangeMake(0, CFDataGetLength(data)), tmp_buffer); buffer = (guint8 *) tmp_buffer; buffer_size = CFDataGetLength(data); CFRelease(data); } profile_source = g_strdup("osx color profile api"); #elif defined G_OS_WIN32 (void)widget; HDC hdc = GetDC (NULL); if ( hdc!=NULL ) { DWORD len = 0; GetICMProfile (hdc, &len, NULL); gchar *path = g_new (gchar, len); if (GetICMProfile (hdc, &len, path)) { gsize size; g_file_get_contents(path, (gchar**)&buffer, &size, NULL); buffer_size = size; } g_free (path); ReleaseDC (NULL, hdc); } profile_source = g_strdup("windows color profile api"); #endif int profile_changed = buffer_size > 0 && (darktable.control->xprofile_size != buffer_size || memcmp(darktable.control->xprofile_data, buffer, buffer_size) != 0); if(profile_changed) { cmsHPROFILE profile = NULL; char name[512]; // thanks to ufraw for this! g_free(darktable.control->xprofile_data); darktable.control->xprofile_data = buffer; darktable.control->xprofile_size = buffer_size; profile = cmsOpenProfileFromMem(buffer, buffer_size); if(profile) { dt_colorspaces_get_profile_name(profile, "en", "US", name, sizeof(name)); cmsCloseProfile(profile); } dt_print(DT_DEBUG_CONTROL, "[color profile] we got a new screen profile `%s' from the %s (size: %d)\n", *name?name:"(unknown)", profile_source, buffer_size); } pthread_rwlock_unlock(&darktable.control->xprofile_lock); if(profile_changed) dt_control_signal_raise(darktable.signals, DT_SIGNAL_CONTROL_PROFILE_CHANGED); g_free(profile_source); }
void nsCairoScreen::Init () { #ifdef MOZ_ENABLE_GTK2 mAvailRect = mRect = nsRect(0, 0, gdk_screen_width(), gdk_screen_height()); // We need to account for the taskbar, etc in the available rect. // See http://freedesktop.org/Standards/wm-spec/index.html#id2767771 // XXX It doesn't change that often, but we should probably // listen for changes to _NET_WORKAREA. // XXX do we care about _NET_WM_STRUT_PARTIAL? That will // add much more complexity to the code here (our screen // could have a non-rectangular shape), but should // lead to greater accuracy. #if GTK_CHECK_VERSION(2,2,0) GdkWindow *root_window = gdk_get_default_root_window(); #else GdkWindow *root_window = GDK_ROOT_PARENT(); #endif // GTK_CHECK_VERSION(2,2,0) long *workareas; GdkAtom type_returned; int format_returned; int length_returned; #if GTK_CHECK_VERSION(2,0,0) GdkAtom cardinal_atom = gdk_x11_xatom_to_atom(XA_CARDINAL); #else GdkAtom cardinal_atom = (GdkAtom) XA_CARDINAL; #endif gdk_error_trap_push(); // gdk_property_get uses (length + 3) / 4, hence G_MAXLONG - 3 here. if (!gdk_property_get(root_window, gdk_atom_intern ("_NET_WORKAREA", FALSE), cardinal_atom, 0, G_MAXLONG - 3, FALSE, &type_returned, &format_returned, &length_returned, (guchar **) &workareas)) { // This window manager doesn't support the freedesktop standard. // Nothing we can do about it, so assume full screen size. return; } // Flush the X queue to catch errors now. gdk_flush(); if (!gdk_error_trap_pop() && type_returned == cardinal_atom && length_returned && (length_returned % 4) == 0 && format_returned == 32) { int num_items = length_returned / sizeof(long); for (int i = 0; i < num_items; i += 4) { nsRect workarea(workareas[i], workareas[i + 1], workareas[i + 2], workareas[i + 3]); if (!mRect.Contains(workarea)) { NS_WARNING("Invalid bounds"); continue; } mAvailRect.IntersectRect(mAvailRect, workarea); } } #elif MOZ_ENABLE_XLIB mScreenNum = 0; mRect.x = mAvailRect.x = 0; mRect.y = mAvailRect.y = 0; mRect.width = mAvailRect.width = 1600; mRect.height = mAvailRect.height = 1200; #endif }
static cmsHPROFILE cdisplay_lcms_get_display_profile (CdisplayLcms *lcms) { GimpColorConfig *config; cmsHPROFILE profile = NULL; config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms)); #if defined GDK_WINDOWING_X11 if (config->display_profile_from_gdk) { GdkScreen *screen; GdkAtom type = GDK_NONE; gint format = 0; gint nitems = 0; gint monitor = 0; gchar *atom_name; guchar *data = NULL; screen = cdisplay_lcms_get_screen (lcms, &monitor); if (monitor > 0) atom_name = g_strdup_printf ("_ICC_PROFILE_%d", monitor); else atom_name = g_strdup ("_ICC_PROFILE"); if (gdk_property_get (gdk_screen_get_root_window (screen), gdk_atom_intern (atom_name, FALSE), GDK_NONE, 0, 64 * 1024 * 1024, FALSE, &type, &format, &nitems, &data) && nitems > 0) { profile = cmsOpenProfileFromMem (data, nitems); g_free (data); } g_free (atom_name); } #elif defined GDK_WINDOWING_QUARTZ if (config->display_profile_from_gdk) { CMProfileRef prof = NULL; gint monitor = 0; cdisplay_lcms_get_screen (lcms, &monitor); CMGetProfileByAVID (monitor, &prof); if (prof) { CFDataRef data; data = CMProfileCopyICCData (NULL, prof); CMCloseProfile (prof); if (data) { UInt8 *buffer = g_malloc (CFDataGetLength (data)); /* We cannot use CFDataGetBytesPtr(), because that returns * a const pointer where cmsOpenProfileFromMem wants a * non-const pointer. */ CFDataGetBytes (data, CFRangeMake (0, CFDataGetLength (data)), buffer); profile = cmsOpenProfileFromMem (buffer, CFDataGetLength (data)); g_free (buffer); CFRelease (data); } } } #elif defined G_OS_WIN32 if (config->display_profile_from_gdk) { HDC hdc = GetDC (NULL); if (hdc) { gchar *path; gint32 len = 0; GetICMProfile (hdc, &len, NULL); path = g_new (gchar, len); if (GetICMProfile (hdc, &len, path)) profile = cmsOpenProfileFromFile (path, "r"); g_free (path); ReleaseDC (NULL, hdc); } } #endif if (! profile && config->display_profile) profile = cmsOpenProfileFromFile (config->display_profile, "r"); return profile; }
void nsScreenGtk :: Init (GdkWindow *aRootWindow) { // We listen for configure events on the root window to pick up // changes to this rect. We could listen for "size_changed" signals // on the default screen to do this, except that doesn't work with // versions of GDK predating the GdkScreen object. See bug 256646. mAvailRect = mRect = nsIntRect(0, 0, gdk_screen_width(), gdk_screen_height()); #ifdef MOZ_X11 // We need to account for the taskbar, etc in the available rect. // See http://freedesktop.org/Standards/wm-spec/index.html#id2767771 // XXX do we care about _NET_WM_STRUT_PARTIAL? That will // add much more complexity to the code here (our screen // could have a non-rectangular shape), but should // lead to greater accuracy. long *workareas; GdkAtom type_returned; int format_returned; int length_returned; #if GTK_CHECK_VERSION(2,0,0) GdkAtom cardinal_atom = gdk_x11_xatom_to_atom(XA_CARDINAL); #else GdkAtom cardinal_atom = (GdkAtom) XA_CARDINAL; #endif gdk_error_trap_push(); // gdk_property_get uses (length + 3) / 4, hence G_MAXLONG - 3 here. if (!gdk_property_get(aRootWindow, gdk_atom_intern ("_NET_WORKAREA", FALSE), cardinal_atom, 0, G_MAXLONG - 3, FALSE, &type_returned, &format_returned, &length_returned, (guchar **) &workareas)) { // This window manager doesn't support the freedesktop standard. // Nothing we can do about it, so assume full screen size. return; } // Flush the X queue to catch errors now. gdk_flush(); if (!gdk_error_trap_pop() && type_returned == cardinal_atom && length_returned && (length_returned % 4) == 0 && format_returned == 32) { int num_items = length_returned / sizeof(long); for (int i = 0; i < num_items; i += 4) { nsIntRect workarea(workareas[i], workareas[i + 1], workareas[i + 2], workareas[i + 3]); if (!mRect.Contains(workarea)) { // Note that we hit this when processing screen size changes, // since we'll get the configure event before the toolbars have // been moved. We'll end up cleaning this up when we get the // change notification to the _NET_WORKAREA property. However, // we still want to listen to both, so we'll handle changes // properly for desktop environments that don't set the // _NET_WORKAREA property. NS_WARNING("Invalid bounds"); continue; } mAvailRect.IntersectRect(mAvailRect, workarea); } } g_free (workareas); #endif }
gboolean fm_dnd_dest_drag_drop(FmDndDest* dd, GdkDragContext *drag_context, GdkAtom target, guint time) { gboolean ret = FALSE; GtkWidget* dest_widget = dd->widget; int i; for(i = 0; i < G_N_ELEMENTS(fm_default_dnd_dest_targets); ++i) { if(gdk_atom_intern_static_string(fm_default_dnd_dest_targets[i].target) == target) { ret = TRUE; break; } } if(ret) /* we support this kind of target */ { if(i == FM_DND_DEST_TARGET_XDS) /* if this is XDS */ { guchar *data = NULL; gint len = 0; GdkAtom text_atom = gdk_atom_intern_static_string("text/plain"); /* get filename from the source window */ if(gdk_property_get(drag_context->source_window, xds_target_atom, text_atom, 0, 1024, FALSE, NULL, NULL, &len, &data) && data) { FmFileInfo* dest = fm_dnd_dest_get_dest_file(dd); if( dest && fm_file_info_is_dir(dest) ) { FmPath* path = fm_path_new_child(dest->path, data); char* uri = fm_path_to_uri(path); /* setup the property */ gdk_property_change(GDK_DRAWABLE(drag_context->source_window), xds_target_atom, text_atom, 8, GDK_PROP_MODE_REPLACE, (const guchar *)uri, strlen(uri) + 1); fm_path_unref(path); g_free(uri); } } else { fm_show_error(gtk_widget_get_toplevel(dest_widget), _("XDirectSave failed.")); gdk_property_change(GDK_DRAWABLE(drag_context->source_window), xds_target_atom, text_atom, 8, GDK_PROP_MODE_REPLACE, (const guchar *)"", 0); } g_free(data); gtk_drag_get_data(dest_widget, drag_context, target, time); /* we should call gtk_drag_finish later in data-received callback. */ return TRUE; } /* see if the drag files are cached */ if(dd->src_files) { /* emit files-dropped signal */ g_signal_emit(dd, signals[FILES_DROPPED], 0, drag_context->action, dd->info_type, dd->src_files, &ret); } else /* we don't have the data */ { if(dd->waiting_data) /* if we're still waiting for the data */ { /* FIXME: how to handle this? */ ret = FALSE; } else ret = FALSE; } gtk_drag_finish(drag_context, ret, FALSE, time); } return ret; }
/** * gimp_monitor_get_color_profile: * @monitor: a #GdkMonitor * * This function returns the #GimpColorProfile of @monitor * or %NULL if there is no profile configured. * * Since: 3.0 * * Return value: the monitor's #GimpColorProfile, or %NULL. **/ GimpColorProfile * gimp_monitor_get_color_profile (GdkMonitor *monitor) { GdkDisplay *display; GdkScreen *screen; GimpColorProfile *profile = NULL; g_return_val_if_fail (GDK_IS_MONITOR (monitor), NULL); display = gdk_monitor_get_display (monitor); #if defined GDK_WINDOWING_X11 { GdkAtom type = GDK_NONE; gint format = 0; gint nitems = 0; gint number; gchar *atom_name; guchar *data = NULL; number = monitor_number (monitor); if (number > 0) atom_name = g_strdup_printf ("_ICC_PROFILE_%d", number); else atom_name = g_strdup ("_ICC_PROFILE"); screen = gdk_display_get_default_screen (display); if (gdk_property_get (gdk_screen_get_root_window (screen), gdk_atom_intern (atom_name, FALSE), GDK_NONE, 0, 64 * 1024 * 1024, FALSE, &type, &format, &nitems, &data) && nitems > 0) { profile = gimp_color_profile_new_from_icc_profile (data, nitems, NULL); g_free (data); } g_free (atom_name); } #elif defined GDK_WINDOWING_QUARTZ { CGColorSpaceRef space = NULL; space = CGDisplayCopyColorSpace (monitor_number (monitor)); if (space) { CFDataRef data; data = CGColorSpaceCopyICCData (space); if (data) { UInt8 *buffer = g_malloc (CFDataGetLength (data)); /* We cannot use CFDataGetBytesPtr(), because that returns * a const pointer where cmsOpenProfileFromMem wants a * non-const pointer. */ CFDataGetBytes (data, CFRangeMake (0, CFDataGetLength (data)), buffer); profile = gimp_color_profile_new_from_icc_profile (buffer, CFDataGetLength (data), NULL); g_free (buffer); CFRelease (data); } CFRelease (space); } } #elif defined G_OS_WIN32 { HDC hdc = GetDC (NULL); if (hdc) { gchar *path; gint32 len = 0; GetICMProfile (hdc, (LPDWORD) &len, NULL); path = g_new (gchar, len); if (GetICMProfile (hdc, (LPDWORD) &len, path)) { GFile *file = g_file_new_for_path (path); profile = gimp_color_profile_new_from_file (file, NULL); g_object_unref (file); } g_free (path); ReleaseDC (NULL, hdc); } } #endif return profile; }
static gboolean handle_real_button_press_event (GtkWidget* base, GdkEventButton* event) { Handle * self; gboolean result = FALSE; GdkEventButton _tmp0_; guint _tmp1_; gint _tmp2_; gint _tmp3_; GdkRectangle _tmp4_ = {0}; GdkRectangle _tmp5_; gint x = 0; gint y = 0; GtkWidget* _tmp115_ = NULL; GtkWindow* _tmp116_; GtkWindow* toplevel; GtkWindow* _tmp117_; gint _tmp118_ = 0; gint _tmp119_ = 0; GdkEventButton _tmp120_; gdouble _tmp121_; gint _tmp122_; GdkEventButton _tmp123_; gdouble _tmp124_; gint _tmp125_; self = (Handle*) base; g_return_val_if_fail (event != NULL, FALSE); _tmp0_ = *event; _tmp1_ = _tmp0_.button; if (_tmp1_ != ((guint) 1)) { result = FALSE; return result; } _tmp2_ = G_MAXINT; _tmp3_ = G_MAXINT; memset (&_tmp4_, 0, sizeof (GdkRectangle)); _tmp4_.x = 0; _tmp4_.y = 0; _tmp4_.width = _tmp2_; _tmp4_.height = _tmp3_; self->priv->m_workarea = _tmp4_; _tmp5_ = self->priv->m_workarea; { gboolean _tmp6_; _tmp6_ = TRUE; while (TRUE) { gboolean _tmp7_; GdkWindow* _tmp8_ = NULL; GdkWindow* _tmp9_; GdkWindow* root; GdkAtom _tmp10_ = 0U; GdkAtom property; GdkAtom _tmp11_ = 0U; GdkAtom type; GdkAtom actual_type = 0U; gint format = 0; guchar* data = NULL; gint data_length1 = 0; gint _data_size_ = 0; gboolean _result_ = FALSE; GdkWindow* _tmp12_; GdkAtom _tmp13_; GdkAtom _tmp14_; glong _tmp15_; GdkAtom _tmp16_ = 0U; gint _tmp17_ = 0; guint8* _tmp18_ = NULL; gint _tmp19_ = 0; gboolean _tmp20_ = FALSE; gboolean _tmp21_ = FALSE; gboolean _tmp22_ = FALSE; gboolean _tmp23_ = FALSE; gboolean _tmp24_; gboolean _tmp27_; gboolean _tmp29_; gboolean _tmp31_; guchar* _tmp32_; gint _tmp32__length1; guchar _tmp33_; guchar* _tmp34_; gint _tmp34__length1; guchar _tmp35_; guchar* _tmp36_; gint _tmp36__length1; guchar _tmp37_; guchar* _tmp38_; gint _tmp38__length1; guchar _tmp39_; gint index; GdkAtom _tmp40_ = 0U; GdkAtom _tmp41_ = 0U; GdkWindow* _tmp42_; GdkAtom _tmp43_; GdkAtom _tmp44_; glong _tmp45_; GdkAtom _tmp46_ = 0U; gint _tmp47_ = 0; guint8* _tmp48_ = NULL; gint _tmp49_ = 0; gboolean _tmp50_ = FALSE; gboolean _tmp51_ = FALSE; gboolean _tmp52_ = FALSE; gboolean _tmp53_ = FALSE; gboolean _tmp54_; gboolean _tmp57_; gboolean _tmp59_; gboolean _tmp62_; gint _tmp63_; gint i; guchar* _tmp64_; gint _tmp64__length1; gint _tmp65_; guchar _tmp66_; guchar* _tmp67_; gint _tmp67__length1; gint _tmp68_; guchar _tmp69_; guchar* _tmp70_; gint _tmp70__length1; gint _tmp71_; guchar _tmp72_; guchar* _tmp73_; gint _tmp73__length1; gint _tmp74_; guchar _tmp75_; gint _tmp76_; guchar* _tmp77_; gint _tmp77__length1; gint _tmp78_; guchar _tmp79_; guchar* _tmp80_; gint _tmp80__length1; gint _tmp81_; guchar _tmp82_; guchar* _tmp83_; gint _tmp83__length1; gint _tmp84_; guchar _tmp85_; guchar* _tmp86_; gint _tmp86__length1; gint _tmp87_; guchar _tmp88_; gint _tmp89_; guchar* _tmp90_; gint _tmp90__length1; gint _tmp91_; guchar _tmp92_; guchar* _tmp93_; gint _tmp93__length1; gint _tmp94_; guchar _tmp95_; guchar* _tmp96_; gint _tmp96__length1; gint _tmp97_; guchar _tmp98_; guchar* _tmp99_; gint _tmp99__length1; gint _tmp100_; guchar _tmp101_; gint _tmp102_; guchar* _tmp103_; gint _tmp103__length1; gint _tmp104_; guchar _tmp105_; guchar* _tmp106_; gint _tmp106__length1; gint _tmp107_; guchar _tmp108_; guchar* _tmp109_; gint _tmp109__length1; gint _tmp110_; guchar _tmp111_; guchar* _tmp112_; gint _tmp112__length1; gint _tmp113_; guchar _tmp114_; _tmp7_ = _tmp6_; if (!_tmp7_) { if (!FALSE) { break; } } _tmp6_ = FALSE; _tmp8_ = gdk_get_default_root_window (); _tmp9_ = _g_object_ref0 (_tmp8_); root = _tmp9_; _tmp10_ = gdk_atom_intern ("_NET_CURRENT_DESKTOP", FALSE); property = _tmp10_; _tmp11_ = gdk_atom_intern ("CARDINAL", FALSE); type = _tmp11_; _tmp12_ = root; _tmp13_ = property; _tmp14_ = type; _tmp15_ = G_MAXLONG; _tmp20_ = gdk_property_get (_tmp12_, _tmp13_, _tmp14_, (gulong) 0, (gulong) _tmp15_, 0, &_tmp16_, &_tmp17_, &_tmp19_, &_tmp18_); actual_type = _tmp16_; format = _tmp17_; data = (g_free (data), NULL); data = _tmp18_; data_length1 = _tmp19_; _data_size_ = data_length1; _result_ = _tmp20_; _tmp24_ = _result_; if (!_tmp24_) { _tmp23_ = TRUE; } else { GdkAtom _tmp25_; GdkAtom _tmp26_; _tmp25_ = actual_type; _tmp26_ = type; _tmp23_ = _tmp25_ != _tmp26_; } _tmp27_ = _tmp23_; if (_tmp27_) { _tmp22_ = TRUE; } else { gint _tmp28_; _tmp28_ = format; _tmp22_ = _tmp28_ != 32; } _tmp29_ = _tmp22_; if (_tmp29_) { _tmp21_ = TRUE; } else { guchar* _tmp30_; gint _tmp30__length1; _tmp30_ = data; _tmp30__length1 = data_length1; _tmp21_ = _tmp30__length1 != 4; } _tmp31_ = _tmp21_; if (_tmp31_) { data = (g_free (data), NULL); _g_object_unref0 (root); break; } _tmp32_ = data; _tmp32__length1 = data_length1; _tmp33_ = _tmp32_[0]; _tmp34_ = data; _tmp34__length1 = data_length1; _tmp35_ = _tmp34_[1]; _tmp36_ = data; _tmp36__length1 = data_length1; _tmp37_ = _tmp36_[2]; _tmp38_ = data; _tmp38__length1 = data_length1; _tmp39_ = _tmp38_[3]; index = (gint) (((_tmp33_ | (_tmp35_ << 8)) | (_tmp37_ << 16)) | (_tmp39_ << 24)); _tmp40_ = gdk_atom_intern ("_NET_WORKAREA", FALSE); property = _tmp40_; _tmp41_ = gdk_atom_intern ("CARDINAL", FALSE); type = _tmp41_; _tmp42_ = root; _tmp43_ = property; _tmp44_ = type; _tmp45_ = G_MAXLONG; _tmp50_ = gdk_property_get (_tmp42_, _tmp43_, _tmp44_, (gulong) 0, (gulong) _tmp45_, 0, &_tmp46_, &_tmp47_, &_tmp49_, &_tmp48_); actual_type = _tmp46_; format = _tmp47_; data = (g_free (data), NULL); data = _tmp48_; data_length1 = _tmp49_; _data_size_ = data_length1; _result_ = _tmp50_; _tmp54_ = _result_; if (!_tmp54_) { _tmp53_ = TRUE; } else { GdkAtom _tmp55_; GdkAtom _tmp56_; _tmp55_ = actual_type; _tmp56_ = type; _tmp53_ = _tmp55_ != _tmp56_; } _tmp57_ = _tmp53_; if (_tmp57_) { _tmp52_ = TRUE; } else { gint _tmp58_; _tmp58_ = format; _tmp52_ = _tmp58_ != 32; } _tmp59_ = _tmp52_; if (_tmp59_) { _tmp51_ = TRUE; } else { guchar* _tmp60_; gint _tmp60__length1; gint _tmp61_; _tmp60_ = data; _tmp60__length1 = data_length1; _tmp61_ = index; _tmp51_ = _tmp60__length1 < ((_tmp61_ + 1) * 16); } _tmp62_ = _tmp51_; if (_tmp62_) { data = (g_free (data), NULL); _g_object_unref0 (root); break; } _tmp63_ = index; i = (_tmp63_ * 4) * 4; _tmp64_ = data; _tmp64__length1 = data_length1; _tmp65_ = i; _tmp66_ = _tmp64_[_tmp65_]; _tmp67_ = data; _tmp67__length1 = data_length1; _tmp68_ = i; _tmp69_ = _tmp67_[_tmp68_ + 1]; _tmp70_ = data; _tmp70__length1 = data_length1; _tmp71_ = i; _tmp72_ = _tmp70_[_tmp71_ + 2]; _tmp73_ = data; _tmp73__length1 = data_length1; _tmp74_ = i; _tmp75_ = _tmp73_[_tmp74_ + 3]; self->priv->m_workarea.x = (gint) (((_tmp66_ | (_tmp69_ << 8)) | (_tmp72_ << 16)) | (_tmp75_ << 24)); _tmp76_ = i; i = _tmp76_ + 4; _tmp77_ = data; _tmp77__length1 = data_length1; _tmp78_ = i; _tmp79_ = _tmp77_[_tmp78_]; _tmp80_ = data; _tmp80__length1 = data_length1; _tmp81_ = i; _tmp82_ = _tmp80_[_tmp81_ + 1]; _tmp83_ = data; _tmp83__length1 = data_length1; _tmp84_ = i; _tmp85_ = _tmp83_[_tmp84_ + 2]; _tmp86_ = data; _tmp86__length1 = data_length1; _tmp87_ = i; _tmp88_ = _tmp86_[_tmp87_ + 3]; self->priv->m_workarea.y = (gint) (((_tmp79_ | (_tmp82_ << 8)) | (_tmp85_ << 16)) | (_tmp88_ << 24)); _tmp89_ = i; i = _tmp89_ + 4; _tmp90_ = data; _tmp90__length1 = data_length1; _tmp91_ = i; _tmp92_ = _tmp90_[_tmp91_]; _tmp93_ = data; _tmp93__length1 = data_length1; _tmp94_ = i; _tmp95_ = _tmp93_[_tmp94_ + 1]; _tmp96_ = data; _tmp96__length1 = data_length1; _tmp97_ = i; _tmp98_ = _tmp96_[_tmp97_ + 2]; _tmp99_ = data; _tmp99__length1 = data_length1; _tmp100_ = i; _tmp101_ = _tmp99_[_tmp100_ + 3]; self->priv->m_workarea.width = (gint) (((_tmp92_ | (_tmp95_ << 8)) | (_tmp98_ << 16)) | (_tmp101_ << 24)); _tmp102_ = i; i = _tmp102_ + 4; _tmp103_ = data; _tmp103__length1 = data_length1; _tmp104_ = i; _tmp105_ = _tmp103_[_tmp104_]; _tmp106_ = data; _tmp106__length1 = data_length1; _tmp107_ = i; _tmp108_ = _tmp106_[_tmp107_ + 1]; _tmp109_ = data; _tmp109__length1 = data_length1; _tmp110_ = i; _tmp111_ = _tmp109_[_tmp110_ + 2]; _tmp112_ = data; _tmp112__length1 = data_length1; _tmp113_ = i; _tmp114_ = _tmp112_[_tmp113_ + 3]; self->priv->m_workarea.height = (gint) (((_tmp105_ | (_tmp108_ << 8)) | (_tmp111_ << 16)) | (_tmp114_ << 24)); data = (g_free (data), NULL); _g_object_unref0 (root); } } self->priv->m_move_begined = TRUE; _tmp115_ = gtk_widget_get_toplevel ((GtkWidget*) self); _tmp116_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp115_, GTK_TYPE_WINDOW, GtkWindow)); toplevel = _tmp116_; _tmp117_ = toplevel; gtk_window_get_position (_tmp117_, &_tmp118_, &_tmp119_); x = _tmp118_; y = _tmp119_; _tmp120_ = *event; _tmp121_ = _tmp120_.x_root; _tmp122_ = x; self->priv->m_press_pos.x = ((gint) _tmp121_) - _tmp122_; _tmp123_ = *event; _tmp124_ = _tmp123_.y_root; _tmp125_ = y; self->priv->m_press_pos.y = ((gint) _tmp124_) - _tmp125_; g_signal_emit_by_name (self, "move-begin"); result = TRUE; _g_object_unref0 (toplevel); return result; }
GimpColorProfile * gimp_widget_get_color_profile (GtkWidget *widget) { GimpColorProfile *profile = NULL; GdkScreen *screen; gint monitor; g_return_val_if_fail (widget == NULL || GTK_IS_WIDGET (widget), NULL); if (widget) { screen = gtk_widget_get_screen (widget); monitor = gimp_widget_get_monitor (widget); } else { screen = gdk_screen_get_default (); monitor = 0; } #if defined GDK_WINDOWING_X11 { GdkAtom type = GDK_NONE; gint format = 0; gint nitems = 0; gchar *atom_name; guchar *data = NULL; if (monitor > 0) atom_name = g_strdup_printf ("_ICC_PROFILE_%d", monitor); else atom_name = g_strdup ("_ICC_PROFILE"); if (gdk_property_get (gdk_screen_get_root_window (screen), gdk_atom_intern (atom_name, FALSE), GDK_NONE, 0, 64 * 1024 * 1024, FALSE, &type, &format, &nitems, &data) && nitems > 0) { profile = gimp_color_profile_new_from_icc_profile (data, nitems, NULL); g_free (data); } g_free (atom_name); } #elif defined GDK_WINDOWING_QUARTZ { CMProfileRef prof = NULL; CMGetProfileByAVID (monitor, &prof); if (prof) { CFDataRef data; data = CMProfileCopyICCData (NULL, prof); CMCloseProfile (prof); if (data) { UInt8 *buffer = g_malloc (CFDataGetLength (data)); /* We cannot use CFDataGetBytesPtr(), because that returns * a const pointer where cmsOpenProfileFromMem wants a * non-const pointer. */ CFDataGetBytes (data, CFRangeMake (0, CFDataGetLength (data)), buffer); profile = gimp_color_profile_new_from_icc_profile (data, CFDataGetLength (data), NULL); g_free (buffer); CFRelease (data); } } } #elif defined G_OS_WIN32 { HDC hdc = GetDC (NULL); if (hdc) { gchar *path; gint32 len = 0; GetICMProfile (hdc, &len, NULL); path = g_new (gchar, len); if (GetICMProfile (hdc, &len, path)) { GFile *file = g_file_new_for_path (path); profile = gimp_color_profile_new_from_file (file, NULL); g_object_unref (file); } g_free (path); ReleaseDC (NULL, hdc); } } #endif return profile; }
gboolean pre_event_handler (GtkWidget *widget, GdkEvent *event, jobject peer) { GtkWidget *event_widget; static guint32 button_click_time = 0; static GdkWindow *button_window = NULL; static guint button_number = -1; static jint click_count = 1; /* If it is not a focus change event, the widget must be realized already. If not, ignore the event (Gtk+ will do the same). */ if (!(event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))) return FALSE; /* Do not handle propagated events. AWT has its own propagation rules */ gdk_window_get_user_data (event->any.window, (void **) &event_widget); if (event_widget != widget) return FALSE; /* We only care about input events */ if (!(event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE || event->type == GDK_ENTER_NOTIFY || event->type == GDK_LEAVE_NOTIFY || event->type == GDK_CONFIGURE || event->type == GDK_EXPOSE || event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE || event->type == GDK_FOCUS_CHANGE || event->type == GDK_MOTION_NOTIFY)) { return FALSE; } /* g_print("event %u widget %s peer %p\n", event->type, gtk_widget_get_name (widget), peer); */ /* If it has no jobject associated we can send no AWT event */ if (!peer) return FALSE; /* for all input events, which have a window with a jobject attached, send the AWT input event corresponding to the Gtk event off to Java */ /* keep track of clickCount ourselves, since the AWT allows more than a triple click to occur */ if (event->type == GDK_BUTTON_PRESS) { if ((event->button.time < (button_click_time + MULTI_CLICK_TIME)) && (event->button.window == button_window) && (event->button.button == button_number)) click_count++; else click_count = 1; button_click_time = event->button.time; button_window = event->button.window; button_number = event->button.button; } switch (event->type) { case GDK_BUTTON_PRESS: (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID, AWT_MOUSE_PRESSED, (jlong)event->button.time, state_to_awt_mods (event->button.state) | button_to_awt_mods (event->button.button), (jint)event->button.x, (jint)event->button.y, click_count, (event->button.button == 3) ? JNI_TRUE : JNI_FALSE); break; case GDK_BUTTON_RELEASE: { int width, height; (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID, AWT_MOUSE_RELEASED, (jlong)event->button.time, state_to_awt_mods (event->button.state) | button_to_awt_mods (event->button.button), (jint)event->button.x, (jint)event->button.y, click_count, JNI_FALSE); /* check to see if the release occured in the window it was pressed in, and if so, generate an AWT click event */ gdk_window_get_size (event->any.window, &width, &height); if (event->button.x >= 0 && event->button.y >= 0 && event->button.x <= width && event->button.y <= height) { (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID, AWT_MOUSE_CLICKED, (jlong)event->button.time, state_to_awt_mods (event->button.state) | button_to_awt_mods (event->button.button), (jint)event->button.x, (jint)event->button.y, click_count, JNI_FALSE); } } break; case GDK_MOTION_NOTIFY: (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID, AWT_MOUSE_MOVED, (jlong)event->motion.time, state_to_awt_mods (event->motion.state), (jint)event->motion.x, (jint)event->motion.y, 0, JNI_FALSE); if (event->motion.state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | GDK_BUTTON5_MASK)) { (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID, AWT_MOUSE_DRAGGED, (jlong)event->motion.time, state_to_awt_mods (event->motion.state), (jint)event->motion.x, (jint)event->motion.y, 0, JNI_FALSE); } break; case GDK_ENTER_NOTIFY: (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID, AWT_MOUSE_ENTERED, (jlong)event->crossing.time, state_to_awt_mods (event->crossing.state), (jint)event->crossing.x, (jint)event->crossing.y, 0, JNI_FALSE); break; case GDK_LEAVE_NOTIFY: if (event->crossing.mode == GDK_CROSSING_NORMAL) (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID, AWT_MOUSE_EXITED, (jlong)event->crossing.time, state_to_awt_mods (event->crossing.state), (jint)event->crossing.x, (jint)event->crossing.y, 0, JNI_FALSE); break; case GDK_CONFIGURE: { /* GtkWidget *widget; gdk_window_get_user_data (event->any.window, (void **) &widget); */ if (widget && GTK_WIDGET_TOPLEVEL (widget)) { /* Configure events are not posted to the AWT event queue, and as such, the gdk/gtk peer functions will be called back before postConfigureEvent returns. */ gdk_threads_leave (); (*gdk_env)->CallVoidMethod (gdk_env, peer, postConfigureEventID, (jint) event->configure.x, (jint) event->configure.y, (jint) event->configure.width, (jint) event->configure.height); gdk_threads_enter (); } } break; case GDK_EXPOSE: { (*gdk_env)->CallVoidMethod (gdk_env, peer, postExposeEventID, (jint)event->expose.area.x, (jint)event->expose.area.y, (jint)event->expose.area.width, (jint)event->expose.area.height); } break; case GDK_FOCUS_CHANGE: (*gdk_env)->CallVoidMethod (gdk_env, peer, postFocusEventID, (jint) (event->focus_change.in) ? AWT_FOCUS_GAINED : AWT_FOCUS_LOST, JNI_FALSE); break; case GDK_KEY_PRESS: case GDK_KEY_RELEASE: { GdkWindow *obj_window; jobject *focus_obj_ptr = NULL; int generates_key_typed = 0; /* A widget with a grab will get key events */ if (!GTK_IS_WINDOW (widget)) focus_obj_ptr = &peer; else { GtkWindow *window; /* Check if we have an enabled focused widget in this window. If not don't handle the event. */ window = GTK_WINDOW (widget); if (!window->focus_widget || !GTK_WIDGET_IS_SENSITIVE (window->focus_widget) || !window->focus_widget->window) return FALSE; /* TextArea peers are attached to the scrolled window that contains the GtkTextView, not to the text view itself. Same for List. */ if (GTK_IS_TEXT_VIEW (window->focus_widget) || GTK_IS_CLIST (window->focus_widget)) { obj_window = gtk_widget_get_parent (window->focus_widget)->window; } else if (GTK_IS_BUTTON (window->focus_widget)) /* GtkButton events go to the "event_window" and this is what we registered when the button was created. */ obj_window = GTK_BUTTON (window->focus_widget)->event_window; else obj_window = window->focus_widget->window; gdk_property_get (obj_window, gdk_atom_intern ("_GNU_GTKAWT_ADDR", FALSE), gdk_atom_intern ("CARDINAL", FALSE), 0, sizeof (jobject), FALSE, NULL, NULL, NULL, (guchar **)&focus_obj_ptr); /* If the window has no jobject attached we can't send anything */ if (!focus_obj_ptr) return FALSE; /* Should we generate an AWT_KEY_TYPED event? */ generates_key_typed = generates_key_typed_event (event, window->focus_widget); } if (event->type == GDK_KEY_PRESS) { (*gdk_env)->CallVoidMethod (gdk_env, *focus_obj_ptr, postKeyEventID, (jint) AWT_KEY_PRESSED, (jlong) event->key.time, keyevent_state_to_awt_mods (event), keysym_to_awt_keycode (event), keyevent_to_awt_keychar (event), keysym_to_awt_keylocation (event)); if (generates_key_typed) { (*gdk_env)->CallVoidMethod (gdk_env, *focus_obj_ptr, postKeyEventID, (jint) AWT_KEY_TYPED, (jlong) event->key.time, state_to_awt_mods (event->key.state), VK_UNDEFINED, keyevent_to_awt_keychar (event), AWT_KEY_LOCATION_UNKNOWN); } } else /* GDK_KEY_RELEASE */ { (*gdk_env)->CallVoidMethod (gdk_env, *focus_obj_ptr, postKeyEventID, (jint) AWT_KEY_RELEASED, (jlong) event->key.time, keyevent_state_to_awt_mods (event), keysym_to_awt_keycode (event), keyevent_to_awt_keychar (event), keysym_to_awt_keylocation (event)); } } break; default: break; } return FALSE; }