Fixed not setting of completion colors.
Removed disabling of scrollbars.
This can be done for gtk2 via ~/.gtkrc-2.0:
style "vimp-no-scrollbars" {
GtkScrollbar::slider-width=0
GtkScrollbar::trough-border=0
}
widget "vimp*" style "vimp-no-scrollbars"
and for gtk3 via XDG_CONFIG_HOME/gtk-3.0/gtk.css
#vimp GtkScrollbar {
-GtkRange-slider-width: 0;
-GtkRange-trough-border: 0;
}
MANDIR ?= $(PREFIX)/share/man/
#----------------compile options---------------------
-LIBS = gtk+-2.0 webkit-1.0 libsoup-2.4
+LIBS = libsoup-2.4
+
+GTK3LIBS=gtk+-3.0 webkitgtk-3.0
+GTK2LIBS=gtk+-2.0 webkit-1.0
+
+ifeq (${GTK}, 3)
+ifeq ($(shell pkg-config --exists $(GTK3LIBS) && echo 1), 1) #has gtk3 libs
+LIBS += $(GTK3LIBS)
+USEGTK3 = 1
+else
+LIBS += $(GTK2LIBS)
+endif
+else
+LIBS += $(GTK2LIBS)
+endif
CFLAGS += $(shell pkg-config --cflags $(LIBS))
CFLAGS += -Wall
CPPFLAGS += -DPROJECT=\"$(PROJECT)\"
CPPFLAGS += -DVERSION=\"${VERSION}\"
+ifeq ($(USEGTK3), 1)
+CPPFLAGS += -DHAS_GTK3
+endif
+
#----------------developer options-------------------
DFLAGS += $(CFLAGS)
# default config
nmap gf source
-nmap : input
+nmap <shift-:> input
nmap o inputopen
nmap O inputopencurrent
nmap d quit
static GList* completion_init_completion(GList* target, GList* source, const gchar* prefix);
static GList* completion_update(GList* completion, GList* active, gboolean back);
static void completion_show(gboolean back);
-static void completion_set_color(Completion* completion, const GdkColor* fg, const GdkColor* bg, PangoFontDescription* font);
+static void completion_set_color(Completion* completion, const VpColor* fg, const VpColor* bg, PangoFontDescription* font);
static void completion_set_entry_text(Completion* completion);
static Completion* completion_get_new(const gchar* label, const gchar* prefix);
}
/* create new completion */
-#if _HAS_GTK3
+#ifdef HAS_GTK3
vp.gui.compbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_set_homogeneous(GTK_BOX(vp.gui.compbox), TRUE);
#else
}
}
-static void completion_set_color(Completion* completion, const GdkColor* fg, const GdkColor* bg, PangoFontDescription* font)
+static void completion_set_color(Completion* completion, const VpColor* fg, const VpColor* bg, PangoFontDescription* font)
{
- gtk_widget_modify_fg(completion->label, GTK_STATE_NORMAL, fg);
- gtk_widget_modify_bg(completion->event, GTK_STATE_NORMAL, bg);
- gtk_widget_modify_font(completion->label, font);
+ VP_WIDGET_OVERRIDE_COLOR(completion->label, GTK_STATE_NORMAL, fg);
+ VP_WIDGET_OVERRIDE_BACKGROUND(completion->event, GTK_STATE_NORMAL, bg);
+ VP_WIDGET_OVERRIDE_FONT(completion->label, font);
}
static void completion_set_entry_text(Completion* completion)
c->event = gtk_event_box_new();
c->prefix = g_strdup(prefix);
-#if _HAS_GTK3
+#ifdef HAS_GTK3
GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous(GTK_BOX(hbox), TRUE);
#else
GSList* link;
for (link = keys; link != NULL; link = link->next) {
Keybind* keybind = (Keybind*)link->data;
-
if (keybind->keyval == keyval
&& keybind->modmask == modmask
&& keybind->modkey == modkey
keybind->modkey = str[0];
keybind->keyval = str[1];
} else {
- /* special handling for shift tab */
- /* TODO find a better solution for such cases */
- if (g_ascii_strcasecmp(str, "<shift-tab>") == 0) {
- keybind->keyval = GDK_ISO_Left_Tab;
- return;
- }
/* keybind has keys like "<tab>" or <ctrl-a> */
if (str[0] == '<') {
/* no modkey set */
}
g_strfreev(string);
}
+
+ /* post process the keybinding */
+ /* special handling for shift tab */
+ if (keybind->keyval == GDK_Tab && keybind->modmask == GDK_SHIFT_MASK) {
+ keybind->keyval = GDK_ISO_Left_Tab;
+ }
}
static guint keybind_str_to_modmask(const gchar* str)
static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* event)
{
- GdkModifierType irrelevant;
- guint keyval;
- static GdkKeymap *keymap;
-
- keymap = gdk_keymap_get_default();
-
- /* Get a mask of modifiers that shouldn't be considered for this event.
- * E.g.: It shouldn't matter whether ';' is shifted or not. */
- gdk_keymap_translate_keyboard_state(keymap, event->hardware_keycode,
- event->state, event->group, &keyval, NULL, NULL, &irrelevant);
+ static GdkModifierType modifiers;
+ modifiers = gtk_accelerator_get_default_mod_mask();
+ guint keyval = event->keyval;
+ guint state = (event->state & modifiers);
/* check for escape or modkeys or counts */
- if ((CLEAN(event->state) & ~irrelevant) == 0) {
- if (IS_ESCAPE(event)) {
- completion_clean();
- /* switch to normal mode and clear the input box */
- Arg a = {VP_MODE_NORMAL, ""};
- vp_set_mode(&a);
+ if (keyval == GDK_Escape && state == 0) {
+ completion_clean();
+ /* switch to normal mode and clear the input box */
+ Arg a = {VP_MODE_NORMAL, ""};
+ vp_set_mode(&a);
+
+ return TRUE;
+ }
+ /* allow mode keys and counts only in normal mode */
+ if (VP_MODE_NORMAL == vp.state.mode) {
+ if (vp.state.modkey == 0 && ((keyval >= GDK_1 && keyval <= GDK_9)
+ || (keyval == GDK_0 && vp.state.count))) {
+ /* append the new entered count to previous one */
+ vp.state.count = (vp.state.count ? vp.state.count * 10 : 0) + (keyval - GDK_0);
+ vp_update_statusbar();
return TRUE;
}
- /* allow mode keys and counts only in normal mode */
- if (VP_MODE_NORMAL == vp.state.mode) {
- if (vp.state.modkey == 0 && ((event->keyval >= GDK_1 && event->keyval <= GDK_9)
- || (event->keyval == GDK_0 && vp.state.count))) {
- /* append the new entered count to previous one */
- vp.state.count = (vp.state.count ? vp.state.count * 10 : 0) + (event->keyval - GDK_0);
- vp_update_statusbar();
-
- return TRUE;
- }
- if (strchr(modkeys->str, event->keyval) && vp.state.modkey != event->keyval) {
- vp.state.modkey = (gchar)event->keyval;
- vp_update_statusbar();
-
- return TRUE;
- }
- }
- }
+ if (strchr(modkeys->str, keyval) && vp.state.modkey != keyval) {
+ vp.state.modkey = (gchar)keyval;
+ vp_update_statusbar();
-#if 0
- /* TODO should we use a command for that too? */
- if (CLEAN_MODE(vp.state.mode) == VP_MODE_COMMAND
- && (event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab)
- ) {
- completion_complete(event->keyval == GDK_ISO_Left_Tab);
- return TRUE;
+ return TRUE;
+ }
}
-#endif
/* check for keybinding */
- GSList* link = keybind_find(CLEAN_MODE(vp.state.mode), vp.state.modkey,
- (CLEAN(event->state) & ~irrelevant), keyval);
+ GSList* link = keybind_find(CLEAN_MODE(vp.state.mode), vp.state.modkey, state, keyval);
if (link) {
Keybind* keybind = (Keybind*)link->data;
#define KEYBIND_H
#include <gdk/gdkkeysyms.h>
-
-/* the CLEAN_MOD_*_MASK defines have all the bits set that will be stripped from the modifier bit field */
-#define CLEAN_MOD_NUMLOCK_MASK (GDK_MOD2_MASK)
-#define CLEAN_MOD_BUTTON_MASK (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK|GDK_BUTTON3_MASK|GDK_BUTTON4_MASK|GDK_BUTTON5_MASK)
-
-/* remove unused bits, numlock symbol and buttons from keymask */
-#define CLEAN(mask) (mask & (GDK_MODIFIER_MASK) & ~(CLEAN_MOD_NUMLOCK_MASK) & ~(CLEAN_MOD_BUTTON_MASK))
-#define IS_ESCAPE(event) (IS_ESCAPE_KEY(CLEAN(event->state), event->keyval))
-#define IS_ESCAPE_KEY(s, k) ((s == 0 && k == GDK_Escape) || (s == GDK_CONTROL_MASK && k == GDK_c))
+#include <gdk/gdkkeysyms-compat.h>
typedef struct {
int mode; /* mode maks for allowed browser modes */
/* callbacks */
static void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec, gpointer user_data);
static void vp_destroy_window_cb(GtkWidget* widget, GtkWidget* window, gpointer user_data);
-static gboolean vp_frame_scrollbar_policy_changed_cb(void);
static void vp_inputbox_activate_cb(GtkEntry* entry, gpointer user_data);
static gboolean vp_inputbox_keyrelease_cb(GtkEntry* entry, GdkEventKey* event);
static void vp_scroll_cb(GtkAdjustment* adjustment, gpointer data);
command_close(0);
}
-static gboolean vp_frame_scrollbar_policy_changed_cb(void)
-{
- return TRUE;
-}
-
static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data)
{
gboolean success = FALSE;
}
static void vp_scroll_cb(GtkAdjustment* adjustment, gpointer data)
-{
+{
vp_update_statusbar();
-}
+}
#ifdef FEATURE_COOKIE
static void vp_new_request_cb(SoupSession* session, SoupMessage *message, gpointer data)
{
Gui* gui = &vp.gui;
- gui->sb_h = GTK_SCROLLBAR(gtk_hscrollbar_new(NULL));
- gui->sb_v = GTK_SCROLLBAR(gtk_vscrollbar_new(NULL));
- gui->adjust_h = gtk_range_get_adjustment(GTK_RANGE(gui->sb_h));
- gui->adjust_v = gtk_range_get_adjustment(GTK_RANGE(gui->sb_v));
-
GdkGeometry hints = {10, 10};
gui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_wmclass(GTK_WINDOW(gui->window), PROJECT, PROJECT);
gtk_window_set_title(GTK_WINDOW(gui->window), PROJECT);
gtk_window_set_geometry_hints(GTK_WINDOW(gui->window), NULL, &hints, GDK_HINT_MIN_SIZE);
gtk_window_set_icon(GTK_WINDOW(gui->window), NULL);
+ gtk_widget_set_name(GTK_WIDGET(gui->window), PROJECT);
/* Create a browser instance */
gui->webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
#endif
/* Create a scrollable area */
- gui->viewport = gtk_scrolled_window_new(gui->adjust_h, gui->adjust_v);
- gtk_scrolled_window_set_policy(
- GTK_SCROLLED_WINDOW(gui->viewport),
- GTK_POLICY_NEVER, GTK_POLICY_NEVER
- );
-
- gui->box = GTK_BOX(gtk_vbox_new(FALSE, 0));
+ gui->viewport = gtk_scrolled_window_new(NULL, NULL);
+ gui->adjust_h = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(gui->viewport));
+ gui->adjust_v = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(gui->viewport));
/* Prepare the imputbox */
gui->inputbox = gtk_entry_new();
gtk_entry_set_inner_border(GTK_ENTRY(gui->inputbox), NULL);
g_object_set(gtk_widget_get_settings(gui->inputbox), "gtk-entry-select-on-focus", FALSE, NULL);
- /* Prepare the statusbar */
+#ifdef HAS_GTK3
+ gui->box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
+ gui->statusbar.box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0));
+#else
+ gui->box = GTK_BOX(gtk_vbox_new(FALSE, 0));
gui->statusbar.box = GTK_BOX(gtk_hbox_new(FALSE, 0));
+#endif
gui->statusbar.left = gtk_label_new(NULL);
gui->statusbar.right = gtk_label_new(NULL);
g_free(path);
}
-void vp_set_widget_font(GtkWidget* widget, const GdkColor* fg, const GdkColor* bg, PangoFontDescription* font)
+void vp_set_widget_font(GtkWidget* widget, const VpColor* fg, const VpColor* bg, PangoFontDescription* font)
{
- gtk_widget_modify_font(widget, font);
- gtk_widget_modify_text(widget, GTK_STATE_NORMAL, fg);
- gtk_widget_modify_base(widget, GTK_STATE_NORMAL, bg);
+ VP_WIDGET_OVERRIDE_FONT(widget, font);
+ VP_WIDGET_OVERRIDE_TEXT(widget, GTK_STATE_NORMAL, fg);
+ VP_WIDGET_OVERRIDE_BASE(widget, GTK_STATE_NORMAL, bg);
}
static void vp_setup_signals(void)
{
Gui* gui = &vp.gui;
- WebKitWebFrame *frame = webkit_web_view_get_main_frame(gui->webview);
/* Set up callbacks so that if either the main window or the browser
* instance is closed, the program will exit */
g_signal_connect(gui->window, "destroy", G_CALLBACK(vp_destroy_window_cb), NULL);
- g_signal_connect(G_OBJECT(frame), "scrollbars-policy-changed", G_CALLBACK(vp_frame_scrollbar_policy_changed_cb), NULL);
g_signal_connect(G_OBJECT(gui->webview), "notify::load-status", G_CALLBACK(vp_webview_load_status_cb), NULL);
g_object_connect(
#define CLEAN_MODE(mode) ((mode) & ~(VP_MODE_COMPLETE))
#define CLEAR_INPUT() (vp_echo(VP_MSG_NORMAL, ""))
+#ifdef HAS_GTK3
+#define VpColor GdkRGBA
+#define VP_COLOR_PARSE(color, string) (gdk_rgba_parse(color, string))
+#define VP_WIDGET_OVERRIDE_BACKGROUND gtk_widget_override_background_color
+#define VP_WIDGET_OVERRIDE_BASE gtk_widget_override_background_color
+#define VP_WIDGET_OVERRIDE_COLOR gtk_widget_override_color
+#define VP_WIDGET_OVERRIDE_TEXT gtk_widget_override_color
+#define VP_WIDGET_OVERRIDE_FONT gtk_widget_override_font
+#else
+#define VpColor GdkColor
+#define VP_COLOR_PARSE(color, string) (gdk_color_parse(string, color))
+#define VP_WIDGET_OVERRIDE_BACKGROUND gtk_widget_modify_bg
+#define VP_WIDGET_OVERRIDE_BASE gtk_widget_modify_base
+#define VP_WIDGET_OVERRIDE_COLOR gtk_widget_modify_fg
+#define VP_WIDGET_OVERRIDE_TEXT gtk_widget_modify_text
+#define VP_WIDGET_OVERRIDE_FONT gtk_widget_modify_font
+#endif
+
/* enums */
typedef enum _vp_mode {
VP_MODE_NORMAL = 1<<0,
} Completions;
typedef struct {
- GdkColor input_fg[VP_MSG_LAST];
- GdkColor input_bg[VP_MSG_LAST];
+ VpColor input_fg[VP_MSG_LAST];
+ VpColor input_bg[VP_MSG_LAST];
PangoFontDescription* input_font[VP_MSG_LAST];
- GdkColor comp_fg[VP_COMP_LAST];
- GdkColor comp_bg[VP_COMP_LAST];
+ VpColor comp_fg[VP_COMP_LAST];
+ VpColor comp_bg[VP_COMP_LAST];
PangoFontDescription* comp_font[VP_COMP_LAST];
} Style;
void vp_update_urlbar(const gchar* uri);
void vp_echo(const MessageType type, gboolean hide, const char *error, ...);
gboolean vp_set_mode(const Arg* arg);
-void vp_set_widget_font(GtkWidget* widget, const GdkColor* fg, const GdkColor* bg, PangoFontDescription* font);
+void vp_set_widget_font(GtkWidget* widget, const VpColor* fg, const VpColor* bg, PangoFontDescription* font);
gboolean vp_load_uri(const Arg* arg);
void vp_clean_up(void);
static gboolean setting_status_color_bg(const Setting* s)
{
- GdkColor color;
+ VpColor color;
- gdk_color_parse(s->arg.s, &color);
- gtk_widget_modify_bg(vp.gui.eventbox, GTK_STATE_NORMAL, &color);
- gtk_widget_modify_bg(GTK_WIDGET(vp.gui.statusbar.left), GTK_STATE_NORMAL, &color);
- gtk_widget_modify_bg(GTK_WIDGET(vp.gui.statusbar.right), GTK_STATE_NORMAL, &color);
+ VP_COLOR_PARSE(&color, s->arg.s);
+ VP_WIDGET_OVERRIDE_BACKGROUND(vp.gui.eventbox, GTK_STATE_NORMAL, &color);
+ VP_WIDGET_OVERRIDE_BACKGROUND(GTK_WIDGET(vp.gui.statusbar.left), GTK_STATE_NORMAL, &color);
+ VP_WIDGET_OVERRIDE_BACKGROUND(GTK_WIDGET(vp.gui.statusbar.right), GTK_STATE_NORMAL, &color);
return TRUE;
}
static gboolean setting_status_color_fg(const Setting* s)
{
- GdkColor color;
+ VpColor color;
- gdk_color_parse(s->arg.s, &color);
- gtk_widget_modify_fg(vp.gui.eventbox, GTK_STATE_NORMAL, &color);
- gtk_widget_modify_fg(GTK_WIDGET(vp.gui.statusbar.left), GTK_STATE_NORMAL, &color);
- gtk_widget_modify_fg(GTK_WIDGET(vp.gui.statusbar.right), GTK_STATE_NORMAL, &color);
+ VP_COLOR_PARSE(&color, s->arg.s);
+ VP_WIDGET_OVERRIDE_COLOR(vp.gui.eventbox, GTK_STATE_NORMAL, &color);
+ VP_WIDGET_OVERRIDE_COLOR(GTK_WIDGET(vp.gui.statusbar.left), GTK_STATE_NORMAL, &color);
+ VP_WIDGET_OVERRIDE_COLOR(GTK_WIDGET(vp.gui.statusbar.right), GTK_STATE_NORMAL, &color);
return TRUE;
}
PangoFontDescription* font;
font = pango_font_description_from_string(s->arg.s);
- gtk_widget_modify_font(vp.gui.eventbox, font);
- gtk_widget_modify_font(GTK_WIDGET(vp.gui.statusbar.left), font);
- gtk_widget_modify_font(GTK_WIDGET(vp.gui.statusbar.right), font);
+ VP_WIDGET_OVERRIDE_FONT(vp.gui.eventbox, font);
+ VP_WIDGET_OVERRIDE_FONT(GTK_WIDGET(vp.gui.statusbar.left), font);
+ VP_WIDGET_OVERRIDE_FONT(GTK_WIDGET(vp.gui.statusbar.right), font);
pango_font_description_free(font);
MessageType type = g_str_has_suffix(s->name, "normal") ? VP_MSG_NORMAL : VP_MSG_ERROR;
if (g_str_has_prefix(s->name, "input-bg")) {
- gdk_color_parse(s->arg.s, &style->input_bg[type]);
+ VP_COLOR_PARSE(&style->input_bg[type], s->arg.s);
} else if (g_str_has_prefix(s->name, "input-fg")) {
- gdk_color_parse(s->name, &style->input_fg[type]);
+ VP_COLOR_PARSE(&style->input_fg[type], s->arg.s);
} else if (g_str_has_prefix(s->arg.s, "input-font")) {
if (style->input_font[type]) {
pango_font_description_free(style->input_font[type]);
CompletionStyle type = g_str_has_suffix(s->name, "normal") ? VP_COMP_NORMAL : VP_COMP_ACTIVE;
if (g_str_has_prefix(s->name, "completion-bg")) {
- gdk_color_parse(s->arg.s, &style->comp_bg[type]);
+ VP_COLOR_PARSE(&style->comp_bg[type], s->arg.s);
} else if (g_str_has_prefix(s->name, "completion-fg")) {
- gdk_color_parse(s->name, &style->comp_fg[type]);
+ VP_COLOR_PARSE(&style->comp_fg[type], s->arg.s);
} else if (g_str_has_prefix(s->arg.s, "completion-font")) {
if (style->comp_font[type]) {
pango_font_description_free(style->comp_font[type]);