Commit 00aa57dd authored by Sebastian Ramacher's avatar Sebastian Ramacher

Subclass GtkEntry for proper Shift+Insert handling

Signed-off-by: default avatarSebastian Ramacher <sebastian@ramacher.at>
parent 5516b7b5
#include "entry.h"
#include <stdbool.h>
G_DEFINE_TYPE(GiraraEntry, girara_entry, GTK_TYPE_ENTRY)
static void girara_entry_paste_primary(GiraraEntry* self);
enum {
PASTE_PRIMARY,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void
girara_entry_class_init(GiraraEntryClass* klass)
{
klass->paste_primary = girara_entry_paste_primary;
signals[PASTE_PRIMARY] =
g_signal_new("paste-primary",
GIRARA_TYPE_ENTRY,
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET(GiraraEntryClass, paste_primary),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 0);
GtkBindingSet* binding_set = gtk_binding_set_by_class(klass);
gtk_binding_entry_add_signal(binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
"paste-primary", 0);
}
static void
girara_entry_init(GiraraEntry* GIRARA_UNUSED(self))
{
}
GiraraEntry*
girara_entry_new(void)
{
GObject* ret = g_object_new(GIRARA_TYPE_ENTRY, NULL);
if (ret == NULL) {
return NULL;
}
return GIRARA_ENTRY(ret);
}
static void
girara_entry_paste_primary(GiraraEntry* self)
{
GValue editable = G_VALUE_INIT;
g_value_init(&editable, G_TYPE_BOOLEAN);
g_object_get_property(G_OBJECT(self), "editable", &editable);
if (g_value_get_boolean(&editable) == true) {
gchar* text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
if (text != NULL) {
int pos = gtk_editable_get_position(GTK_EDITABLE(self));
gtk_editable_insert_text(GTK_EDITABLE(self), text, -1, &pos);
gtk_editable_set_position(GTK_EDITABLE(self), pos);
}
} else {
gtk_widget_error_bell(GTK_WIDGET(self));
}
}
#ifndef GIRARA_ENTRY_H
#define GIRARA_ENTRY_H
#include <gtk/gtk.h>
#include "macros.h"
/*
* Type macros.
*/
#define GIRARA_TYPE_ENTRY \
(girara_entry_get_type())
#define GIRARA_ENTRY(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), GIRARA_TYPE_ENTRY, GiraraEntry))
#define GIRARA_IS_ENTRY(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GIRARA_TYPE_ENTRY))
#define GIRARA_ENTRY_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), GIRARA_TYPE_ENTRY, GiraraEntryClass))
#define GIRARA_IS_ENTRY_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GIRARA_TYPE_ENTRY))
#define GIRARA_ENTRY_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), GIRARA_TYPE_ENTRY, GiraraEntryClass))
typedef struct girara_entry_s GiraraEntry;
typedef struct girara_entry_class_s GiraraEntryClass;
struct girara_entry_s
{
/* Parent instance structure */
GtkEntry parent_instance;
/* instance members */
};
struct girara_entry_class_s
{
/* Parent class structure */
GtkEntryClass parent_class;
/* class members */
void (*paste_primary)(GiraraEntry*);
};
GType girara_entry_get_type(void) GIRARA_HIDDEN;
GiraraEntry* girara_entry_new(void) GIRARA_HIDDEN;
#endif
......@@ -14,6 +14,7 @@
#include "config.h"
#include "css-definitions.h"
#include "datastructures.h"
#include "entry.h"
#include "input-history.h"
#include "internal.h"
#include "settings.h"
......@@ -289,7 +290,7 @@ girara_session_create()
session->gtk.notification_area = gtk_event_box_new();
session->gtk.notification_text = gtk_label_new(NULL);
session->gtk.inputbar_dialog = GTK_LABEL(gtk_label_new(NULL));
session->gtk.inputbar_entry = GTK_ENTRY(gtk_entry_new());
session->gtk.inputbar_entry = GTK_ENTRY(girara_entry_new());
session->gtk.inputbar = gtk_event_box_new();
session->gtk.tabs = GTK_NOTEBOOK(gtk_notebook_new());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment