static void tap_and_hold_simulate_click (GtkWidget *w, gpointer btn_ptr) { GdkEvent *press; GdkEvent *release; guint button; button = GPOINTER_TO_UINT (btn_ptr); press = g_object_get_data (G_OBJECT (w), "press"); if (press) { /* Generate a release event for button 1 */ release = gdk_event_copy (press); release->button.type = GDK_BUTTON_RELEASE; release->button.state = GDK_BUTTON1_MASK; /* Make the press event right/middle click */ press->button.button = button; /* Release button 1 */ gtk_main_do_event (release); /* Simulate click */ gtk_main_do_event (press); /* Free the release event - the press one is * freed in tap_and_hold_button_press_filter() */ gdk_event_free (release); } }
static void gtk_scale_button_release_grab (GtkScaleButton *button, GdkEventButton *event) { GdkEventButton *e; GdkDisplay *display; GtkScaleButtonPrivate *priv; priv = button->priv; /* ungrab focus */ display = gtk_widget_get_display (GTK_WIDGET (button)); gdk_display_keyboard_ungrab (display, event->time); gdk_display_pointer_ungrab (display, event->time); gtk_grab_remove (priv->dock); /* hide again */ gtk_widget_hide (priv->dock); priv->timeout = FALSE; e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event); e->window = GTK_WIDGET (button)->window; e->type = GDK_BUTTON_RELEASE; gtk_widget_event (GTK_WIDGET (button), (GdkEvent *) e); e->window = event->window; gdk_event_free ((GdkEvent *) e); }
static gboolean emitKeyStroke(WebKitWebView* webView) { GdkEvent* pressEvent = gdk_event_new(GDK_KEY_PRESS); pressEvent->key.keyval = GDK_KEY_f; GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(webView)); pressEvent->key.window = window; g_object_ref(pressEvent->key.window); #ifndef GTK_API_VERSION_2 GdkDeviceManager* manager = gdk_display_get_device_manager(gdk_window_get_display(window)); gdk_event_set_device(pressEvent, gdk_device_manager_get_client_pointer(manager)); #endif // When synthesizing an event, an invalid hardware_keycode value // can cause it to be badly processed by Gtk+. GdkKeymapKey* keys; gint n_keys; if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), GDK_KEY_f, &keys, &n_keys)) { pressEvent->key.hardware_keycode = keys[0].keycode; g_free(keys); } GdkEvent* releaseEvent = gdk_event_copy(pressEvent); gtk_main_do_event(pressEvent); gdk_event_free(pressEvent); releaseEvent->key.type = GDK_KEY_RELEASE; gtk_main_do_event(releaseEvent); gdk_event_free(releaseEvent); return FALSE; }
static void main_do_event(GdkEvent *event, wxArrayPtrVoid *queue) { switch (event->type) { case GDK_NOTHING: // Ignore it break; case GDK_SELECTION_REQUEST: case GDK_SELECTION_NOTIFY: case GDK_SELECTION_CLEAR: #if GTK_CHECK_VERSION(2,6,0) case GDK_OWNER_CHANGE: #endif // process it now gtk_main_do_event(event); break; default: // process it later (but make a copy; the caller will free the event pointer) queue->Add(gdk_event_copy(event)); break; } // don't allow idle callbacks while we're active wxTheApp->SuspendIdleCallback(); return; }
gboolean button_press_cb (GtkWidget* window, GdkEventButton* event) { (void) window; gint context; gboolean propagate = FALSE, sendev = FALSE; context = get_click_context(NULL); if(event->type == GDK_BUTTON_PRESS) { if(uzbl.state.last_button) gdk_event_free((GdkEvent *)uzbl.state.last_button); uzbl.state.last_button = (GdkEventButton *)gdk_event_copy((GdkEvent *)event); /* left click */ if(event->button == 1) { if((context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE)) send_event(FORM_ACTIVE, NULL, TYPE_NAME, "button1", NULL); else if((context & WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT)) send_event(ROOT_ACTIVE, NULL, TYPE_NAME, "button1", NULL); else { sendev = TRUE; propagate = TRUE; } } else if(event->button == 2 && !(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE)) { sendev = TRUE; propagate = TRUE; } else if(event->button > 3) { sendev = TRUE; propagate = TRUE; } if(sendev) { button_to_event(event->button, event->state, GDK_BUTTON_PRESS); } } if(event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) { if(event->button == 1 && !(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) && (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT)) { sendev = TRUE; propagate = TRUE; } else if(event->button == 2 && !(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE)) { sendev = TRUE; propagate = TRUE; } else if(event->button > 3) { sendev = TRUE; propagate = TRUE; } if(sendev) { button_to_event(event->button, event->state, event->type); } } return propagate; }
void gdk_event_put(GdkEvent * event) { GdkEvent *new_event; g_return_if_fail(event != NULL); new_event = gdk_event_copy(event); gdk_event_queue_append(new_event); }
GdkEvent *gdk_event_peek(void) { GList *tmp_list; tmp_list = gdk_event_queue_find_first(); if (tmp_list) return gdk_event_copy(tmp_list->data); else return NULL; }
static void clutter_backend_gdk_copy_event_data (ClutterBackend *backend, const ClutterEvent *src, ClutterEvent *dest) { GdkEvent *gdk_event; gdk_event = _clutter_event_get_platform_data (src); if (gdk_event != NULL) _clutter_event_set_platform_data (dest, gdk_event_copy (gdk_event)); }
static JSValueRef contextClickCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { GdkEvent* pressEvent = gdk_event_new(GDK_BUTTON_PRESS); if (!prepareMouseButtonEvent(pressEvent, 2, 0)) return JSValueMakeUndefined(context); GdkEvent* releaseEvent = gdk_event_copy(pressEvent); sendOrQueueEvent(pressEvent); releaseEvent->type = GDK_BUTTON_RELEASE; sendOrQueueEvent(releaseEvent); return JSValueMakeUndefined(context); }
/* * hide popup when clicking outside */ static gboolean cb_dock_press (GtkWidget * widget, GdkEventButton * event, gpointer data) { BtVolumePopup *self = BT_VOLUME_POPUP (data); //if(!gtk_widget_get_realized(GTK_WIDGET(self)) return FALSE; if (event->type == GDK_BUTTON_PRESS) { GdkEventButton *e; //GST_INFO("type=%4d, window=%p, send_event=%3d, time=%8d",event->type,event->window,event->send_event,event->time); //GST_INFO("x=%6.4lf, y=%6.4lf, axes=%p, state=%4d",event->x,event->y,event->axes,event->state); //GST_INFO("button=%4d, device=%p, x_root=%6.4lf, y_root=%6.4lf\n",event->button,event->device,event->x_root,event->y_root); /* GtkWidget *parent=GTK_WIDGET(gtk_window_get_transient_for(GTK_WINDOW(self))); //GtkWidget *parent=gtk_widget_get_parent(GTK_WIDGET(self)); //gboolean retval; GST_INFO("FORWARD : popup=%p, widget=%p", self, widget); GST_INFO("FORWARD : parent=%p, parent->window=%p", parent, parent->window); */ bt_volume_popup_hide (self); // forward event e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event); //GST_INFO("type=%4d, window=%p, send_event=%3d, time=%8d",e->type,e->window,e->send_event,e->time); //GST_INFO("x=%6.4lf, y=%6.4lf, axes=%p, state=%4d",e->x,e->y,e->axes,e->state); //GST_INFO("button=%4d, device=%p, x_root=%6.4lf, y_root=%6.4lf\n",e->button,e->device,e->x_root,e->y_root); //e->window = widget->window; //e->window = parent->window; //e->type = GDK_BUTTON_PRESS; gtk_main_do_event ((GdkEvent *) e); //retval=gtk_widget_event (widget, (GdkEvent *) e); //retval=gtk_widget_event (parent, (GdkEvent *) e); //retval=gtk_widget_event (self->parent_widget, (GdkEvent *) e); //GST_INFO(" result =%d", retval); //g_signal_emit_by_name(self->parent_widget, "event", 0, &retval, e); //g_signal_emit_by_name(parent, "event", 0, &retval, e); //GST_INFO(" result =%d", retval); //e->window = event->window; gdk_event_free ((GdkEvent *) e); return TRUE; } return FALSE; }
gboolean button_press_cb (GtkWidget* window, GdkEventButton* event) { (void) window; gint context; gchar *details; gboolean propagate = FALSE, sendev = FALSE; if(event->type == GDK_BUTTON_PRESS) { if(uzbl.state.last_button) gdk_event_free((GdkEvent *)uzbl.state.last_button); uzbl.state.last_button = (GdkEventButton *)gdk_event_copy((GdkEvent *)event); context = get_click_context(NULL); /* left click */ if(event->button == 1) { if((context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE)) send_event(FORM_ACTIVE, "button1", NULL); else if((context & WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT)) send_event(ROOT_ACTIVE, "button1", NULL); } else if(event->button == 2 && !(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE)) { sendev = TRUE; propagate = TRUE; } else if(event->button > 3) { sendev = TRUE; propagate = TRUE; } else if(event->button == 3) { sendev = TRUE; propagate = FALSE; } if(sendev) { details = g_strdup_printf("Button%d", event->button); send_event(KEY_PRESS, details, NULL); g_free(details); } } return propagate; }
static void ide_terminal_do_popup (IdeTerminal *self, const GdkEvent *event) { PopupInfo *popup_info; GtkClipboard *clipboard; g_assert (IDE_IS_TERMINAL (self)); popup_info = g_slice_new0 (PopupInfo); popup_info->event = event ? gdk_event_copy (event) : gtk_get_current_event (); popup_info->terminal = g_object_ref (self); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (self), GDK_SELECTION_CLIPBOARD); gtk_clipboard_request_contents (clipboard, gdk_atom_intern_static_string ("TARGETS"), popup_targets_received, popup_info); }
static gboolean tap_and_hold_button_press_filter (GtkWidget *w, GdkEventButton *e) { GdkEvent *press; if (e->type == GDK_BUTTON_PRESS && e->button == 1) { /* Store button 1 event, so we don't need * to find the pointer coordinates * later */ press = g_object_get_data (G_OBJECT (w), "press"); /* Free the previous stored one */ if (press) gdk_event_free (press); press = gdk_event_copy ((GdkEvent*) e); g_object_set_data (G_OBJECT (w), "press", press); } return FALSE; }
gboolean nemo_query_editor_handle_event (NemoQueryEditor *editor, GdkEventKey *event) { GdkEvent *new_event; gboolean handled = FALSE; gulong id; gboolean retval; gboolean text_changed; char *old_text; const char *new_text; editor->details->got_preedit = FALSE; if (!gtk_widget_get_realized (editor->details->entry)) { gtk_widget_realize (editor->details->entry); } old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (editor->details->entry))); id = g_signal_connect (editor->details->entry, "preedit-changed", G_CALLBACK (entry_preedit_changed_cb), editor); new_event = gdk_event_copy ((GdkEvent *) event); g_object_unref (((GdkEventKey *) new_event)->window); ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (editor->details->entry)); retval = gtk_widget_event (editor->details->entry, new_event); gdk_event_free (new_event); g_signal_handler_disconnect (editor->details->entry, id); new_text = gtk_entry_get_text (GTK_ENTRY (editor->details->entry)); text_changed = strcmp (old_text, new_text) != 0; g_free (old_text); handled = (editor->details->got_preedit) || (retval && text_changed); editor->details->got_preedit = FALSE; return handled; }
void EventSenderProxy::keyDown(WKStringRef keyRef, WKEventModifiers wkModifiers, unsigned location) { guint modifiers = webkitModifiersToGDKModifiers(wkModifiers); int gdkKeySym = getGDKKeySymForKeyRef(keyRef, location, &modifiers); GdkEvent* pressEvent = gdk_event_new(GDK_KEY_PRESS); pressEvent->key.keyval = gdkKeySym; pressEvent->key.state = modifiers; pressEvent->key.window = gtk_widget_get_window(GTK_WIDGET(m_testController->mainWebView()->platformWindow())); g_object_ref(pressEvent->key.window); gdk_event_set_device(pressEvent, gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(pressEvent->key.window)))); GOwnPtr<GdkKeymapKey> keys; gint nKeys; if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), gdkKeySym, &keys.outPtr(), &nKeys)) pressEvent->key.hardware_keycode = keys.get()[0].keycode; GdkEvent* releaseEvent = gdk_event_copy(pressEvent); dispatchEvent(pressEvent); releaseEvent->key.type = GDK_KEY_RELEASE; dispatchEvent(releaseEvent); }
void Ctrl::AddEvent(gpointer user_data, int type, const Value& value, GdkEvent *event) { if(Events.GetCount() > 50000) return; Event& e = Events.AddTail(); e.windowid = (uint32)(uintptr_t)user_data; e.type = type; e.value = value; gint x, y; GdkModifierType mod; gdk_window_get_pointer(gdk_get_default_root_window(), &x, &y, &mod); e.mousepos = Point(x, y); e.state = mod; e.count = 1; e.event = NULL; if(event) { e.time = gdk_event_get_time(event); e.event = gdk_event_copy(event); } else { e.time = gtk_get_current_event_time(); e.event = gtk_get_current_event(); } }
static gboolean egg_tree_multi_drag_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer data) { GtkTreeView *tree_view; GtkTreePath *path = NULL; GtkTreeViewColumn *column = NULL; gint cell_x, cell_y; GtkTreeSelection *selection; EggTreeMultiDndData *priv_data; if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget))) return FALSE; if (event->button == 3) return FALSE; tree_view = GTK_TREE_VIEW (widget); priv_data = g_object_get_data (G_OBJECT (tree_view), EGG_TREE_MULTI_DND_STRING); if (priv_data == NULL) { priv_data = g_new0 (EggTreeMultiDndData, 1); priv_data->pending_event = FALSE; g_object_set_data (G_OBJECT (tree_view), EGG_TREE_MULTI_DND_STRING, priv_data); } if (g_slist_find (priv_data->event_list, event)) return FALSE; if (priv_data->pending_event) { /* save the event to be propagated in order */ priv_data->event_list = g_slist_append (priv_data->event_list, gdk_event_copy ((GdkEvent*)event)); return TRUE; } if (event->type == GDK_2BUTTON_PRESS) return FALSE; gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, &column, &cell_x, &cell_y); selection = gtk_tree_view_get_selection (tree_view); if (path) { gboolean call_parent = (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK) || !gtk_tree_selection_path_is_selected (selection, path) || event->button != 1); if (call_parent) (GTK_WIDGET_GET_CLASS (tree_view))->button_press_event (widget, event); if (gtk_tree_selection_path_is_selected (selection, path)) { priv_data->pressed_button = event->button; priv_data->x = event->x; priv_data->y = event->y; priv_data->pending_event = TRUE; if (!call_parent) priv_data->event_list = g_slist_append (priv_data->event_list, gdk_event_copy ((GdkEvent*)event)); if (priv_data->motion_notify_handler == 0) { priv_data->motion_notify_handler = g_signal_connect (G_OBJECT (tree_view), "motion_notify_event", G_CALLBACK (egg_tree_multi_drag_motion_event), NULL); } if (priv_data->button_release_handler == 0) { priv_data->button_release_handler = g_signal_connect (G_OBJECT (tree_view), "button_release_event", G_CALLBACK (egg_tree_multi_drag_button_release_event), NULL); } if (priv_data->drag_data_get_handler == 0) { priv_data->drag_data_get_handler = g_signal_connect (G_OBJECT (tree_view), "drag_data_get", G_CALLBACK (egg_tree_multi_drag_drag_data_get), NULL); } } gtk_tree_path_free (path); /* We called the default handler so we don't let the default handler run */ return TRUE; } return FALSE; }
void Ctrl::Event::Set(const Event& e) { *(Event0 *)this = e; event = e.event ? gdk_event_copy(e.event) : NULL; }
static gboolean egg_tree_multi_drag_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer data) { GtkTreeView *tree_view; GtkTreePath *path = NULL; GtkTreeViewColumn *column = NULL; gint cell_x, cell_y; GtkTreeSelection *selection; EggTreeMultiDndData *priv_data; tree_view = GTK_TREE_VIEW (widget); priv_data = g_object_get_data (G_OBJECT (tree_view), EGG_TREE_MULTI_DND_STRING); if (priv_data == NULL) { priv_data = g_new0 (EggTreeMultiDndData, 1); g_object_set_data (G_OBJECT (tree_view), EGG_TREE_MULTI_DND_STRING, priv_data); } if (g_slist_find (priv_data->event_list, event)) return FALSE; if (priv_data->event_list) { /* save the event to be propagated in order */ priv_data->event_list = g_slist_append (priv_data->event_list, gdk_event_copy ((GdkEvent*)event)); return TRUE; } if (event->type == GDK_2BUTTON_PRESS) return FALSE; if (event->button == 3) return FALSE; gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, &column, &cell_x, &cell_y); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); if (path && gtk_tree_selection_path_is_selected (selection, path)) { priv_data->pressed_button = event->button; priv_data->x = event->x; priv_data->y = event->y; priv_data->event_list = g_slist_append (priv_data->event_list, gdk_event_copy ((GdkEvent*)event)); priv_data->motion_notify_handler = g_signal_connect (G_OBJECT (tree_view), "motion_notify_event", G_CALLBACK (egg_tree_multi_drag_motion_event), NULL); priv_data->button_release_handler = g_signal_connect (G_OBJECT (tree_view), "button_release_event", G_CALLBACK (egg_tree_multi_drag_button_release_event), NULL); if (priv_data->drag_data_get_handler == 0) { priv_data->drag_data_get_handler = g_signal_connect (G_OBJECT (tree_view), "drag_data_get", G_CALLBACK (egg_tree_multi_drag_drag_data_get), NULL); } gtk_tree_path_free (path); return TRUE; } if (path) { gtk_tree_path_free (path); } return FALSE; }
SV * newSVGdkEvent(GdkEvent * e) { HV * h; GdkEvent * e2; SV * r; int n; if (!e) return newSVsv(&PL_sv_undef); h = newHV(); /*r = newSVMiscRef(e, "Gtk::Gdk::Event", &n);*/ /*h = (HV*)SvRV(r);*/ r = newRV((SV*)h); SvREFCNT_dec(h); sv_bless(r, gv_stashpv("Gtk::Gdk::Event", FALSE)); e2 = gdk_event_copy(e); hv_store(h, "_ptr", 4, newSViv((int)e2), 0); /*printf("Turning GdkEvent %d, type %d, into SV %d, ptr %d\n", e, e->type, r, e2);*/ hv_store(h, "type", 4, newSVGdkEventType(e->type), 0); hv_store(h, "window", 6, newSVGdkWindow(e->any.window), 0); switch (e->type) { case GDK_EXPOSE: hv_store(h, "area", 4, newSVGdkRectangle(&e->expose.area), 0); hv_store(h, "count", 5, newSViv(e->expose.count), 0); break; case GDK_MOTION_NOTIFY: hv_store(h, "is_hint", 7, newSViv(e->motion.is_hint), 0); hv_store(h, "x", 1, newSVnv(e->motion.x), 0); hv_store(h, "y", 1, newSVnv(e->motion.y), 0); hv_store(h, "pressure", 8, newSVnv(e->motion.pressure), 0); hv_store(h, "xtilt", 5, newSVnv(e->motion.xtilt), 0); hv_store(h, "ytilt", 5, newSVnv(e->motion.ytilt), 0); hv_store(h, "time", 4, newSViv(e->motion.time), 0); hv_store(h, "state", 5, newSViv(e->motion.state), 0); hv_store(h, "source", 6, newSVGdkInputSource(e->motion.source), 0); hv_store(h, "deviceid", 8, newSViv(e->motion.deviceid), 0); break; case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: hv_store(h, "x", 1, newSViv(e->button.x), 0); hv_store(h, "y", 1, newSViv(e->button.y), 0); hv_store(h, "time", 4, newSViv(e->button.time), 0); hv_store(h, "pressure", 8, newSVnv(e->motion.pressure), 0); hv_store(h, "xtilt", 5, newSVnv(e->motion.xtilt), 0); hv_store(h, "ytilt", 5, newSVnv(e->motion.ytilt), 0); hv_store(h, "state", 5, newSViv(e->button.state), 0); hv_store(h, "button", 6, newSViv(e->button.button), 0); hv_store(h, "source", 6, newSVGdkInputSource(e->motion.source), 0); hv_store(h, "deviceid", 8, newSViv(e->motion.deviceid), 0); break; case GDK_KEY_PRESS: case GDK_KEY_RELEASE: hv_store(h, "time", 4, newSViv(e->key.time), 0); hv_store(h, "state", 5, newSViv(e->key.state), 0); hv_store(h, "keyval", 6, newSViv(e->key.keyval), 0); break; case GDK_FOCUS_CHANGE: hv_store(h, "in", 2, newSViv(e->focus_change.in), 0); break; case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: hv_store(h, "window", 6, newSVGdkWindow(e->crossing.window), 0); hv_store(h, "subwindow", 9, newSVGdkWindow(e->crossing.subwindow), 0); hv_store(h, "detail", 6, newSVGdkNotifyType(e->crossing.detail), 0); break; case GDK_CONFIGURE: hv_store(h, "x", 1, newSViv(e->configure.x), 0); hv_store(h, "y", 1, newSViv(e->configure.y), 0); hv_store(h, "width", 5, newSViv(e->configure.width), 0); hv_store(h, "height", 6, newSViv(e->configure.height), 0); break; case GDK_PROPERTY_NOTIFY: hv_store(h, "time", 4, newSViv(e->property.time), 0); hv_store(h, "state", 5, newSViv(e->property.state), 0); hv_store(h, "atom", 4, newSVGdkAtom(e->property.atom), 0); break; case GDK_SELECTION_CLEAR: case GDK_SELECTION_REQUEST: case GDK_SELECTION_NOTIFY: hv_store(h, "requestor", 9, newSViv(e->selection.requestor), 0); hv_store(h, "time", 4, newSViv(e->selection.time), 0); hv_store(h, "selection", 9, newSVGdkAtom(e->selection.selection), 0); hv_store(h, "property", 8, newSVGdkAtom(e->selection.property), 0); break; case GDK_PROXIMITY_IN: case GDK_PROXIMITY_OUT: hv_store(h, "time", 4, newSViv(e->proximity.time), 0); hv_store(h, "source", 6, newSVGdkInputSource(e->motion.source), 0); hv_store(h, "deviceid", 8, newSViv(e->motion.deviceid), 0); break; } return r; }
NativeWebKeyboardEvent::NativeWebKeyboardEvent(const NativeWebKeyboardEvent& event) : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(&event.nativeEvent()->key)) , m_nativeEvent(gdk_event_copy(event.nativeEvent())) { }
NativeWebKeyboardEvent::NativeWebKeyboardEvent(GdkEvent* event) : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(&event->key)) , m_nativeEvent(gdk_event_copy(event)) { }
static void wxgtk_main_do_event(GdkEvent* event, void* data) { // categorize the GDK event according to wxEventCategory. // See http://library.gnome.org/devel/gdk/unstable/gdk-Events.html#GdkEventType // for more info. // NOTE: GDK_* constants which were not present in the GDK2.0 can be tested for // only at compile-time; when running the program (compiled with a recent GDK) // on a system with an older GDK lib we can be sure there won't be problems // because event->type will never assume those values corresponding to // new event types (since new event types are always added in GDK with non // conflicting values for ABI compatibility). // Some events (currently only a single one) may be used for more than one // category, so we need 2 variables. The second one will remain "unknown" // in most cases. wxEventCategory cat = wxEVT_CATEGORY_UNKNOWN, cat2 = wxEVT_CATEGORY_UNKNOWN; switch (event->type) { case GDK_SELECTION_REQUEST: case GDK_SELECTION_NOTIFY: case GDK_SELECTION_CLEAR: case GDK_OWNER_CHANGE: cat = wxEVT_CATEGORY_CLIPBOARD; break; case GDK_KEY_PRESS: case GDK_KEY_RELEASE: case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: case GDK_SCROLL: // generated from mouse buttons case GDK_CLIENT_EVENT: cat = wxEVT_CATEGORY_USER_INPUT; break; case GDK_PROPERTY_NOTIFY: // This one is special: it can be used for UI purposes but also for // clipboard operations, so allow it in both cases (we probably could // examine the event itself to distinguish between the two cases but // this would be unnecessarily complicated). cat2 = wxEVT_CATEGORY_CLIPBOARD; // Fall through. case GDK_PROXIMITY_IN: case GDK_PROXIMITY_OUT: case GDK_MOTION_NOTIFY: case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: case GDK_VISIBILITY_NOTIFY: case GDK_FOCUS_CHANGE: case GDK_CONFIGURE: case GDK_WINDOW_STATE: case GDK_SETTING: case GDK_DELETE: case GDK_DESTROY: case GDK_EXPOSE: #ifndef __WXGTK3__ case GDK_NO_EXPOSE: #endif case GDK_MAP: case GDK_UNMAP: case GDK_DRAG_ENTER: case GDK_DRAG_LEAVE: case GDK_DRAG_MOTION: case GDK_DRAG_STATUS: case GDK_DROP_START: case GDK_DROP_FINISHED: #if GTK_CHECK_VERSION(2,8,0) case GDK_GRAB_BROKEN: #endif #if GTK_CHECK_VERSION(2,14,0) case GDK_DAMAGE: #endif cat = wxEVT_CATEGORY_UI; break; default: cat = wxEVT_CATEGORY_UNKNOWN; break; } wxGUIEventLoop* evtloop = static_cast<wxGUIEventLoop*>(data); // is this event allowed now? if (evtloop->IsEventAllowedInsideYield(cat) || (cat2 != wxEVT_CATEGORY_UNKNOWN && evtloop->IsEventAllowedInsideYield(cat2))) { // process it now gtk_main_do_event(event); } else if (event->type != GDK_NOTHING) { // process it later (but make a copy; the caller will free the event // pointer) evtloop->StoreGdkEventForLaterProcessing(gdk_event_copy(event)); } }
static gboolean fcitx_im_context_filter_keypress(GtkIMContext *context, GdkEventKey *event) { FcitxLog(LOG_LEVEL, "fcitx_im_context_filter_keypress"); FcitxIMContext *fcitxcontext = FCITX_IM_CONTEXT(context); /* check this first, since we use key snooper, most key will be handled. */ if (fcitx_client_is_valid(fcitxcontext->client) ) { /* XXX it is a workaround for some applications do not set client window. */ if (fcitxcontext->client_window == NULL && event->window != NULL) { gtk_im_context_set_client_window((GtkIMContext *)fcitxcontext, event->window); /* set_cursor_location_internal() will get origin from X server, * it blocks UI. So delay it to idle callback. */ g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, (GSourceFunc) _set_cursor_location_internal, g_object_ref(fcitxcontext), (GDestroyNotify) g_object_unref); } } if (G_UNLIKELY(event->state & FcitxKeyState_HandledMask)) return TRUE; if (G_UNLIKELY(event->state & FcitxKeyState_IgnoredMask)) return gtk_im_context_filter_keypress(fcitxcontext->slave, event); if (fcitx_client_is_valid(fcitxcontext->client) && fcitxcontext->has_focus) { _request_surrounding_text (fcitxcontext); fcitxcontext->time = event->time; if (_use_sync_mode) { int ret = fcitx_client_process_key_sync(fcitxcontext->client, event->keyval, event->hardware_keycode, event->state, (event->type == GDK_KEY_PRESS) ? (FCITX_PRESS_KEY) : (FCITX_RELEASE_KEY), event->time); if (ret <= 0) { event->state |= FcitxKeyState_IgnoredMask; return gtk_im_context_filter_keypress(fcitxcontext->slave, event); } else { event->state |= FcitxKeyState_HandledMask; return TRUE; } } else { ProcessKeyStruct* pks = g_malloc0(sizeof(ProcessKeyStruct)); pks->context = fcitxcontext; pks->event = (GdkEventKey *) gdk_event_copy((GdkEvent *) event); fcitx_client_process_key(fcitxcontext->client, _fcitx_im_context_process_key_cb, pks, event->keyval, event->hardware_keycode, event->state, (event->type == GDK_KEY_PRESS) ? (FCITX_PRESS_KEY) : (FCITX_RELEASE_KEY), event->time); event->state |= FcitxKeyState_HandledMask; return TRUE; } } else { return gtk_im_context_filter_keypress(fcitxcontext->slave, event); } return FALSE; }
static gboolean gtk_scale_popup (GtkWidget *widget, GdkEvent *event, guint32 time) { GtkScaleButton *button; GtkScaleButtonPrivate *priv; GtkAdjustment *adj; gint x, y, m, dx, dy, sx, sy, startoff; gdouble v; GdkDisplay *display; GdkScreen *screen; button = GTK_SCALE_BUTTON (widget); priv = button->priv; adj = priv->adjustment; display = gtk_widget_get_display (widget); screen = gtk_widget_get_screen (widget); /* position roughly */ gtk_window_set_screen (GTK_WINDOW (priv->dock), screen); gdk_window_get_origin (widget->window, &x, &y); x += widget->allocation.x; y += widget->allocation.y; if (priv->orientation == GTK_ORIENTATION_VERTICAL) gtk_window_move (GTK_WINDOW (priv->dock), x, y - (SCALE_SIZE / 2)); else gtk_window_move (GTK_WINDOW (priv->dock), x - (SCALE_SIZE / 2), y); gtk_widget_show_all (priv->dock); gdk_window_get_origin (priv->dock->window, &dx, &dy); dx += priv->dock->allocation.x; dy += priv->dock->allocation.y; gdk_window_get_origin (priv->scale->window, &sx, &sy); sx += priv->scale->allocation.x; sy += priv->scale->allocation.y; priv->timeout = TRUE; /* position (needs widget to be shown already) */ v = gtk_scale_button_get_value (button) / (adj->upper - adj->lower); if (priv->orientation == GTK_ORIENTATION_VERTICAL) { startoff = sy - dy; x += (widget->allocation.width - priv->dock->allocation.width) / 2; y -= startoff; y -= GTK_RANGE (priv->scale)->min_slider_size / 2; m = priv->scale->allocation.height - GTK_RANGE (priv->scale)->min_slider_size; y -= m * (1.0 - v); } else { startoff = sx - dx; x -= startoff; y += (widget->allocation.height - priv->dock->allocation.height) / 2; x -= GTK_RANGE (priv->scale)->min_slider_size / 2; m = priv->scale->allocation.width - GTK_RANGE (priv->scale)->min_slider_size; x -= m * v; } /* Make sure the dock stays inside the monitor */ if (event->type == GDK_BUTTON_PRESS) { int monitor; GdkEventButton *button_event = (GdkEventButton *) event; GdkRectangle rect; GtkWidget *d; d = GTK_WIDGET (priv->dock); monitor = gdk_screen_get_monitor_at_point (screen, button_event->x_root, button_event->y_root); gdk_screen_get_monitor_geometry (screen, monitor, &rect); if (priv->orientation == GTK_ORIENTATION_VERTICAL) y += button_event->y; else x += button_event->x; if (y < rect.y) y = rect.y; else if (y + d->allocation.height > rect.height + rect.y) y = rect.y + rect.height - d->allocation.height; if (x < rect.x) x = rect.x; else if (x + d->allocation.width > rect.width + rect.x) x = rect.x + rect.width - d->allocation.width; } gtk_window_move (GTK_WINDOW (priv->dock), x, y); if (event->type == GDK_BUTTON_PRESS) GTK_WIDGET_CLASS (gtk_scale_button_parent_class)->button_press_event (widget, (GdkEventButton *) event); /* grab focus */ gtk_grab_add (priv->dock); if (gdk_pointer_grab (priv->dock->window, TRUE, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, time) != GDK_GRAB_SUCCESS) { gtk_grab_remove (priv->dock); gtk_widget_hide (priv->dock); return FALSE; } if (gdk_keyboard_grab (priv->dock->window, TRUE, time) != GDK_GRAB_SUCCESS) { gdk_display_pointer_ungrab (display, time); gtk_grab_remove (priv->dock); gtk_widget_hide (priv->dock); return FALSE; } gtk_widget_grab_focus (priv->dock); if (event->type == GDK_BUTTON_PRESS) { GdkEventButton *e; GdkEventButton *button_event = (GdkEventButton *) event; /* forward event to the slider */ e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event); e->window = priv->scale->window; /* position: the X position isn't relevant, halfway will work just fine. * The vertical position should be *exactly* in the middle of the slider * of the scale; if we don't do that correctly, it'll move from its current * position, which means a position change on-click, which is bad. */ if (priv->orientation == GTK_ORIENTATION_VERTICAL) { e->x = priv->scale->allocation.width / 2; m = priv->scale->allocation.height - GTK_RANGE (priv->scale)->min_slider_size; e->y = ((1.0 - v) * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; } else { e->y = priv->scale->allocation.height / 2; m = priv->scale->allocation.width - GTK_RANGE (priv->scale)->min_slider_size; e->x = (v * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; } gtk_widget_event (priv->scale, (GdkEvent *) e); e->window = button_event->window; gdk_event_free ((GdkEvent *) e); } gtk_widget_grab_focus (priv->scale); priv->pop_time = time; return TRUE; }
/* Emits an event for an item in the canvas, be it the current item, grabbed * item, or focused item, as appropriate. */ static int emit_event (GnomeCanvas *canvas, GdkEvent *event) { GdkEvent *ev; gint finished; GnomeCanvasItem *item; GnomeCanvasItem *parent; guint mask; /* Choose where we send the event */ item = canvas->current_item; if (canvas->focused_item && ((event->type == GDK_KEY_PRESS) || (event->type == GDK_KEY_RELEASE) || (event->type == GDK_FOCUS_CHANGE))) item = canvas->focused_item; if (canvas->grabbed_item) item = canvas->grabbed_item; /* Perform checks for grabbed items */ if (canvas->grabbed_item) { switch (event->type) { case GDK_ENTER_NOTIFY: mask = GDK_ENTER_NOTIFY_MASK; break; case GDK_LEAVE_NOTIFY: mask = GDK_LEAVE_NOTIFY_MASK; break; case GDK_MOTION_NOTIFY: mask = GDK_POINTER_MOTION_MASK; break; case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: mask = GDK_BUTTON_PRESS_MASK; break; case GDK_BUTTON_RELEASE: mask = GDK_BUTTON_RELEASE_MASK; break; case GDK_KEY_PRESS: mask = GDK_KEY_PRESS_MASK; break; case GDK_KEY_RELEASE: mask = GDK_KEY_RELEASE_MASK; break; default: mask = 0; break; } if (!(mask & canvas->grabbed_event_mask)) return FALSE; } /* Convert to world coordinates -- we have two cases because of diferent * offsets of the fields in the event structures. */ ev = gdk_event_copy (event); switch (ev->type) { case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: gnome_canvas_window_to_world (canvas, ev->crossing.x, ev->crossing.y, &ev->crossing.x, &ev->crossing.y); break; case GDK_MOTION_NOTIFY: case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: gnome_canvas_window_to_world (canvas, ev->motion.x, ev->motion.y, &ev->motion.x, &ev->motion.y); break; default: break; } /* The event is propagated up the hierarchy (for if someone connected to * a group instead of a leaf event), and emission is stopped if a * handler returns TRUE, just like for GtkWidget events. */ finished = FALSE; while (item && !finished) { g_object_ref (item); g_signal_emit_by_name (item, "event", ev, &finished); parent = item->parent; g_object_unref (item); item = parent; } gdk_event_free (ev); return finished; }
static void wxgtk_main_do_event(GdkEvent *event, wxGUIEventLoop* evtloop) { // categorize the GDK event according to wxEventCategory. // See http://library.gnome.org/devel/gdk/unstable/gdk-Events.html#GdkEventType // for more info. // NOTE: GDK_* constants which were not present in the GDK2.0 can be tested for // only at compile-time; when running the program (compiled with a recent GDK) // on a system with an older GDK lib we can be sure there won't be problems // because event->type will never assume those values corresponding to // new event types (since new event types are always added in GDK with non // conflicting values for ABI compatibility). wxEventCategory cat = wxEVT_CATEGORY_UNKNOWN; switch (event->type) { case GDK_SELECTION_REQUEST: case GDK_SELECTION_NOTIFY: case GDK_SELECTION_CLEAR: #if GTK_CHECK_VERSION(2,6,0) case GDK_OWNER_CHANGE: #endif cat = wxEVT_CATEGORY_CLIPBOARD; break; case GDK_KEY_PRESS: case GDK_KEY_RELEASE: case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: case GDK_SCROLL: // generated from mouse buttons case GDK_CLIENT_EVENT: cat = wxEVT_CATEGORY_USER_INPUT; break; case GDK_PROXIMITY_IN: case GDK_PROXIMITY_OUT: case GDK_MOTION_NOTIFY: case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: case GDK_VISIBILITY_NOTIFY: case GDK_PROPERTY_NOTIFY: case GDK_FOCUS_CHANGE: case GDK_CONFIGURE: case GDK_WINDOW_STATE: case GDK_SETTING: case GDK_DELETE: case GDK_DESTROY: case GDK_EXPOSE: case GDK_NO_EXPOSE: case GDK_MAP: case GDK_UNMAP: case GDK_DRAG_ENTER: case GDK_DRAG_LEAVE: case GDK_DRAG_MOTION: case GDK_DRAG_STATUS: case GDK_DROP_START: case GDK_DROP_FINISHED: #if GTK_CHECK_VERSION(2,8,0) case GDK_GRAB_BROKEN: #endif #if GTK_CHECK_VERSION(2,14,0) case GDK_DAMAGE: #endif cat = wxEVT_CATEGORY_UI; break; default: cat = wxEVT_CATEGORY_UNKNOWN; break; } // is this event allowed now? if (evtloop->IsEventAllowedInsideYield(cat)) gtk_main_do_event(event); // process it now else if (event->type != GDK_NOTHING) evtloop->StoreGdkEventForLaterProcessing(gdk_event_copy(event)); // process it later (but make a copy; the caller will free the event pointer) }
static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); static const JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); webkit_web_frame_layout(mainFrame); // handle modifier keys. int state = 0; if (argumentCount > 1) { JSObjectRef modifiersArray = JSValueToObject(context, arguments[1], exception); if (modifiersArray) { for (int i = 0; i < JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty, 0), 0); ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0); JSStringRef string = JSValueToStringCopy(context, value, 0); if (JSStringIsEqualToUTF8CString(string, "ctrlKey")) state |= GDK_CONTROL_MASK; else if (JSStringIsEqualToUTF8CString(string, "shiftKey")) state |= GDK_SHIFT_MASK; else if (JSStringIsEqualToUTF8CString(string, "altKey")) state |= GDK_MOD1_MASK; JSStringRelease(string); } } } // handle location argument. int location = DOM_KEY_LOCATION_STANDARD; if (argumentCount > 2) location = (int)JSValueToNumber(context, arguments[2], exception); JSStringRef character = JSValueToStringCopy(context, arguments[0], exception); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); int gdkKeySym = GDK_VoidSymbol; if (location == DOM_KEY_LOCATION_NUMPAD) { if (JSStringIsEqualToUTF8CString(character, "leftArrow")) gdkKeySym = GDK_KP_Left; else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) gdkKeySym = GDK_KP_Right; else if (JSStringIsEqualToUTF8CString(character, "upArrow")) gdkKeySym = GDK_KP_Up; else if (JSStringIsEqualToUTF8CString(character, "downArrow")) gdkKeySym = GDK_KP_Down; else if (JSStringIsEqualToUTF8CString(character, "pageUp")) gdkKeySym = GDK_KP_Page_Up; else if (JSStringIsEqualToUTF8CString(character, "pageDown")) gdkKeySym = GDK_KP_Page_Down; else if (JSStringIsEqualToUTF8CString(character, "home")) gdkKeySym = GDK_KP_Home; else if (JSStringIsEqualToUTF8CString(character, "end")) gdkKeySym = GDK_KP_End; else if (JSStringIsEqualToUTF8CString(character, "insert")) gdkKeySym = GDK_KP_Insert; else if (JSStringIsEqualToUTF8CString(character, "delete")) gdkKeySym = GDK_KP_Delete; else // If we get some other key specified with the numpad location, // crash here, so we add it sooner rather than later. g_assert_not_reached(); } else { if (JSStringIsEqualToUTF8CString(character, "leftArrow")) gdkKeySym = GDK_Left; else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) gdkKeySym = GDK_Right; else if (JSStringIsEqualToUTF8CString(character, "upArrow")) gdkKeySym = GDK_Up; else if (JSStringIsEqualToUTF8CString(character, "downArrow")) gdkKeySym = GDK_Down; else if (JSStringIsEqualToUTF8CString(character, "pageUp")) gdkKeySym = GDK_Page_Up; else if (JSStringIsEqualToUTF8CString(character, "pageDown")) gdkKeySym = GDK_Page_Down; else if (JSStringIsEqualToUTF8CString(character, "home")) gdkKeySym = GDK_Home; else if (JSStringIsEqualToUTF8CString(character, "end")) gdkKeySym = GDK_End; else if (JSStringIsEqualToUTF8CString(character, "insert")) gdkKeySym = GDK_Insert; else if (JSStringIsEqualToUTF8CString(character, "delete")) gdkKeySym = GDK_Delete; else if (JSStringIsEqualToUTF8CString(character, "printScreen")) gdkKeySym = GDK_Print; else if (JSStringIsEqualToUTF8CString(character, "F1")) gdkKeySym = GDK_F1; else if (JSStringIsEqualToUTF8CString(character, "F2")) gdkKeySym = GDK_F2; else if (JSStringIsEqualToUTF8CString(character, "F3")) gdkKeySym = GDK_F3; else if (JSStringIsEqualToUTF8CString(character, "F4")) gdkKeySym = GDK_F4; else if (JSStringIsEqualToUTF8CString(character, "F5")) gdkKeySym = GDK_F5; else if (JSStringIsEqualToUTF8CString(character, "F6")) gdkKeySym = GDK_F6; else if (JSStringIsEqualToUTF8CString(character, "F7")) gdkKeySym = GDK_F7; else if (JSStringIsEqualToUTF8CString(character, "F8")) gdkKeySym = GDK_F8; else if (JSStringIsEqualToUTF8CString(character, "F9")) gdkKeySym = GDK_F9; else if (JSStringIsEqualToUTF8CString(character, "F10")) gdkKeySym = GDK_F10; else if (JSStringIsEqualToUTF8CString(character, "F11")) gdkKeySym = GDK_F11; else if (JSStringIsEqualToUTF8CString(character, "F12")) gdkKeySym = GDK_F12; else { int charCode = JSStringGetCharactersPtr(character)[0]; if (charCode == '\n' || charCode == '\r') gdkKeySym = GDK_Return; else if (charCode == '\t') gdkKeySym = GDK_Tab; else if (charCode == '\x8') gdkKeySym = GDK_BackSpace; else { gdkKeySym = gdk_unicode_to_keyval(charCode); if (WTF::isASCIIUpper(charCode)) state |= GDK_SHIFT_MASK; } } } JSStringRelease(character); WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); if (!view) return JSValueMakeUndefined(context); // create and send the event GdkEvent* pressEvent = gdk_event_new(GDK_KEY_PRESS); pressEvent->key.keyval = gdkKeySym; pressEvent->key.state = state; pressEvent->key.window = gtk_widget_get_window(GTK_WIDGET(view)); g_object_ref(pressEvent->key.window); #ifndef GTK_API_VERSION_2 gdk_event_set_device(pressEvent, getDefaultGDKPointerDevice(pressEvent->key.window)); #endif // When synthesizing an event, an invalid hardware_keycode value // can cause it to be badly processed by Gtk+. GdkKeymapKey* keys; gint n_keys; if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), gdkKeySym, &keys, &n_keys)) { pressEvent->key.hardware_keycode = keys[0].keycode; g_free(keys); } GdkEvent* releaseEvent = gdk_event_copy(pressEvent); dispatchEvent(pressEvent); releaseEvent->key.type = GDK_KEY_RELEASE; dispatchEvent(releaseEvent); return JSValueMakeUndefined(context); }
static gboolean display_key_press_cb(GtkWidget *widget, GdkEventKey *event, MathDisplay *display) { int state; guint32 c; guint new_keyval = 0; /* Treat keypad keys as numbers even when numlock is off */ switch(event->keyval) { case GDK_KEY_KP_Delete: /* Period without numlock */ new_keyval = GDK_KEY_KP_Decimal; break; case GDK_KEY_KP_Insert: new_keyval = GDK_KEY_0; break; case GDK_KEY_KP_End: new_keyval = GDK_KEY_1; break; case GDK_KEY_KP_Down: new_keyval = GDK_KEY_2; break; case GDK_KEY_KP_Page_Down: new_keyval = GDK_KEY_3; break; case GDK_KEY_KP_Left: new_keyval = GDK_KEY_4; break; case GDK_KEY_KP_Begin: /* This is apparently what "5" does when numlock is off. */ new_keyval = GDK_KEY_5; break; case GDK_KEY_KP_Right: new_keyval = GDK_KEY_6; break; case GDK_KEY_KP_Home: new_keyval = GDK_KEY_7; break; case GDK_KEY_KP_Up: new_keyval = GDK_KEY_8; break; case GDK_KEY_KP_Page_Up: new_keyval = GDK_KEY_9; break; } if (new_keyval) { gboolean result; GdkEvent *new_event; new_event = gdk_event_copy((GdkEvent *)event); ((GdkEventKey *)new_event)->keyval = new_keyval; g_signal_emit_by_name(widget, "key-press-event", new_event, &result); gdk_event_free(new_event); return result; } state = event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK); c = gdk_keyval_to_unicode(event->keyval); /* Solve on enter */ if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter) { math_equation_solve(display->priv->equation); return TRUE; } /* Clear on escape */ if ((event->keyval == GDK_KEY_Escape && state == 0) || (event->keyval == GDK_KEY_BackSpace && state == GDK_CONTROL_MASK) || (event->keyval == GDK_KEY_Delete && state == GDK_SHIFT_MASK)) { math_equation_clear(display->priv->equation); return TRUE; } /* Numeric keypad will often insert '.' regardless of locale */ if (event->keyval == GDK_KEY_KP_Decimal) { math_equation_insert_numeric_point(display->priv->equation); return TRUE; } /* Substitute */ if (state == 0) { if (c == '*') { math_equation_insert(display->priv->equation, "×"); return TRUE; } if (c == '/') { math_equation_insert(display->priv->equation, "÷"); return TRUE; } if (c == '-') { math_equation_insert_subtract(display->priv->equation); return TRUE; } } /* Shortcuts */ if (state == GDK_CONTROL_MASK) { switch(event->keyval) { case GDK_KEY_bracketleft: math_equation_insert(display->priv->equation, "⌈"); return TRUE; case GDK_KEY_bracketright: math_equation_insert(display->priv->equation, "⌉"); return TRUE; case GDK_KEY_e: math_equation_insert_exponent(display->priv->equation); return TRUE; case GDK_KEY_f: math_equation_factorize(display->priv->equation); return TRUE; case GDK_KEY_i: math_equation_insert(display->priv->equation, "⁻¹"); return TRUE; case GDK_KEY_p: math_equation_insert(display->priv->equation, "π"); return TRUE; case GDK_KEY_r: math_equation_insert(display->priv->equation, "√"); return TRUE; case GDK_KEY_u: math_equation_insert(display->priv->equation, "µ"); return TRUE; case GDK_KEY_minus: math_equation_insert(display->priv->equation, "⁻"); return TRUE; case GDK_KEY_apostrophe: math_equation_insert(display->priv->equation, "°"); return TRUE; } } if (state == GDK_MOD1_MASK) { switch(event->keyval) { case GDK_KEY_bracketleft: math_equation_insert(display->priv->equation, "⌊"); return TRUE; case GDK_KEY_bracketright: math_equation_insert(display->priv->equation, "⌋"); return TRUE; } } if (state == GDK_CONTROL_MASK || math_equation_get_number_mode(display->priv->equation) == SUPERSCRIPT) { switch(event->keyval) { case GDK_KEY_0: case GDK_KEY_KP_0: math_equation_insert(display->priv->equation, "⁰"); return TRUE; case GDK_KEY_1: case GDK_KEY_KP_1: math_equation_insert(display->priv->equation, "¹"); return TRUE; case GDK_KEY_2: case GDK_KEY_KP_2: math_equation_insert(display->priv->equation, "²"); return TRUE; case GDK_KEY_3: case GDK_KEY_KP_3: math_equation_insert(display->priv->equation, "³"); return TRUE; case GDK_KEY_4: case GDK_KEY_KP_4: math_equation_insert(display->priv->equation, "⁴"); return TRUE; case GDK_KEY_5: case GDK_KEY_KP_5: math_equation_insert(display->priv->equation, "⁵"); return TRUE; case GDK_KEY_6: case GDK_KEY_KP_6: math_equation_insert(display->priv->equation, "⁶"); return TRUE; case GDK_KEY_7: case GDK_KEY_KP_7: math_equation_insert(display->priv->equation, "⁷"); return TRUE; case GDK_KEY_8: case GDK_KEY_KP_8: math_equation_insert(display->priv->equation, "⁸"); return TRUE; case GDK_KEY_9: case GDK_KEY_KP_9: math_equation_insert(display->priv->equation, "⁹"); return TRUE; } } else if (state == GDK_MOD1_MASK || math_equation_get_number_mode(display->priv->equation) == SUBSCRIPT) { switch(event->keyval) { case GDK_KEY_0: case GDK_KEY_KP_0: math_equation_insert(display->priv->equation, "₀"); return TRUE; case GDK_KEY_1: case GDK_KEY_KP_1: math_equation_insert(display->priv->equation, "₁"); return TRUE; case GDK_KEY_2: case GDK_KEY_KP_2: math_equation_insert(display->priv->equation, "₂"); return TRUE; case GDK_KEY_3: case GDK_KEY_KP_3: math_equation_insert(display->priv->equation, "₃"); return TRUE; case GDK_KEY_4: case GDK_KEY_KP_4: math_equation_insert(display->priv->equation, "₄"); return TRUE; case GDK_KEY_5: case GDK_KEY_KP_5: math_equation_insert(display->priv->equation, "₅"); return TRUE; case GDK_KEY_6: case GDK_KEY_KP_6: math_equation_insert(display->priv->equation, "₆"); return TRUE; case GDK_KEY_7: case GDK_KEY_KP_7: math_equation_insert(display->priv->equation, "₇"); return TRUE; case GDK_KEY_8: case GDK_KEY_KP_8: math_equation_insert(display->priv->equation, "₈"); return TRUE; case GDK_KEY_9: case GDK_KEY_KP_9: math_equation_insert(display->priv->equation, "₉"); return TRUE; } } return FALSE; }
static gint _key_snooper_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data) { gboolean retval = FALSE; FcitxIMContext *fcitxcontext = (FcitxIMContext *) _focus_im_context; if (fcitxcontext == NULL || !fcitxcontext->has_focus) return FALSE; if (G_UNLIKELY (event->state & FcitxKeyState_HandledMask)) return TRUE; if (G_UNLIKELY (event->state & FcitxKeyState_IgnoredMask)) return FALSE; do { if (!fcitx_client_is_valid(fcitxcontext->client)) { break; } _request_surrounding_text (fcitxcontext); fcitxcontext->time = event->time; if (_use_sync_mode) { int ret = fcitx_client_process_key_sync(fcitxcontext->client, event->keyval, event->hardware_keycode, event->state, (event->type == GDK_KEY_PRESS) ? (FCITX_PRESS_KEY) : (FCITX_RELEASE_KEY), event->time); if (ret <= 0) retval = FALSE; else retval = TRUE; } else { ProcessKeyStruct* pks = g_malloc0(sizeof(ProcessKeyStruct)); pks->context = fcitxcontext; pks->event = (GdkEventKey *) gdk_event_copy((GdkEvent *) event); fcitx_client_process_key(fcitxcontext->client, _fcitx_im_context_process_key_cb, pks, event->keyval, event->hardware_keycode, event->state, (event->type == GDK_KEY_PRESS) ? (FCITX_PRESS_KEY) : (FCITX_RELEASE_KEY), event->time); retval = TRUE; } } while(0); if (!retval) { event->state |= FcitxKeyState_IgnoredMask; return FALSE; } else { event->state |= FcitxKeyState_HandledMask; return TRUE; } return retval; }