Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/configsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static cfg_opt_t config_opts[] = {
CFG_STR("fullscreen_key", "F11", CFGF_NONE),
CFG_STR("toggle_transparency_key", "F12", CFGF_NONE),
CFG_STR("toggle_searchbar_key", "<Shift><Control>f", CFGF_NONE),
CFG_STR("pin_key", "<Shift><Control>p", CFGF_NONE),
CFG_STR("closetab_key", "<Shift><Control>w", CFGF_NONE),
CFG_STR("nexttab_key", "<Control>Page_Down", CFGF_NONE),
CFG_STR("prevtab_key", "<Control>Page_Up", CFGF_NONE),
Expand Down Expand Up @@ -153,7 +154,7 @@ static cfg_opt_t config_opts[] = {
CFG_BOOL("scroll_on_key", TRUE, CFGF_NONE),
CFG_BOOL("bell", FALSE, CFGF_NONE),
CFG_BOOL("run_command", FALSE, CFGF_NONE),
CFG_BOOL("pinned", TRUE, CFGF_NONE),
CFG_BOOL("display_on_all_workspaces", TRUE, CFGF_NONE),
CFG_BOOL("animation", FALSE, CFGF_NONE),
CFG_BOOL("hidden", FALSE, CFGF_NONE),
CFG_BOOL("set_as_desktop", FALSE, CFGF_NONE),
Expand Down
42 changes: 41 additions & 1 deletion src/key_grabber.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ static void process_all_pending_gtk_events ()
gdk_display_flush (display);
}

void set_pinned (gboolean value, struct tilda_window_ *tw)
{
tw->is_pinned = value;
if (tw->pin_icon != NULL) {
gtk_widget_set_visible (tw->pin_icon, tw->is_pinned);
}
}

/**
* @force_hide: This option is used by the auto hide feature, so we can ignore the checks to focus tilda instead
* of pulling up.
Expand Down Expand Up @@ -346,7 +354,7 @@ static void pull_down (struct tilda_window_ *tw) {
*
* Note that the "Always on top" property doesn't seem to go away, only this
* property (Show on all desktops) does... */
if (config_getbool ("pinned"))
if (config_getbool ("display_on_all_workspaces"))
gtk_window_stick (GTK_WINDOW (tw->window));

if (config_getbool ("animation") && !tw->fullscreen) {
Expand Down Expand Up @@ -414,9 +422,28 @@ static void onKeybindingPull (G_GNUC_UNUSED const char *keystring, gpointer user
{
DEBUG_FUNCTION("onKeybindingPull");
tilda_window *tw = TILDA_WINDOW(user_data);

/* Only unpin if we're actually going to pull up (hide) the window,
* not if we're just going to focus it */
gboolean needsFocus = !tw->focus_loss_on_keypress
&& !gtk_window_is_active(GTK_WINDOW(tw->window))
&& !tw->hide_non_focused;

if ((tw->current_state == STATE_DOWN) && !needsFocus) {
set_pinned (FALSE, tw); /* Unpin when hiding window */
}

pull (tw, PULL_TOGGLE, FALSE);
}

static void onKeybindingPin (G_GNUC_UNUSED const char *keystring, gpointer user_data)
{
DEBUG_FUNCTION("onKeybindingPin");
tilda_window *tw = TILDA_WINDOW(user_data);

tilda_window_toggle_pin(tw);
}

gboolean tilda_keygrabber_bind (const gchar *keystr, tilda_window *tw)
{
/* Empty strings are no good */
Expand All @@ -431,6 +458,19 @@ void tilda_keygrabber_unbind (const gchar *keystr)
tomboy_keybinder_unbind (keystr, (TomboyBindkeyHandler)onKeybindingPull);
}

gboolean tilda_keygrabber_bind_pin (const gchar *keystr, tilda_window *tw)
{
/* Empty strings are no good */
if (keystr == NULL || strcmp ("", keystr) == 0)
return FALSE;

return tomboy_keybinder_bind (keystr, (TomboyBindkeyHandler)onKeybindingPin, tw);
}

void tilda_keygrabber_unbind_pin (const gchar *keystr)
{
tomboy_keybinder_unbind (keystr, (TomboyBindkeyHandler)onKeybindingPin);
}


/* vim: set ts=4 sts=4 sw=4 expandtab: */
Expand Down
5 changes: 5 additions & 0 deletions src/key_grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ G_BEGIN_DECLS

void pull (struct tilda_window_ *tw, enum pull_action action, gboolean force_hide);

void set_pinned (gboolean value, struct tilda_window_ *tw);

extern void generate_animation_positions (tilda_window *tw);

gboolean tilda_keygrabber_bind (const gchar *keystr, tilda_window *tw);
void tilda_keygrabber_unbind (const gchar *keystr);

gboolean tilda_keygrabber_bind_pin (const gchar *keystr, tilda_window *tw);
void tilda_keygrabber_unbind_pin (const gchar *keystr);

/**
* This function will make the tilda window active after it starts
*/
Expand Down
13 changes: 13 additions & 0 deletions src/tilda-context-menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ menu_searchbar_cb (GSimpleAction *action,
tilda_window_toggle_searchbar (TILDA_WINDOW (user_data));
}

static void
menu_pin_cb (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
DEBUG_FUNCTION ("menu_pin_cb");
DEBUG_ASSERT (user_data != NULL);

tilda_window_toggle_pin (TILDA_WINDOW (user_data));
}

static void
menu_preferences_cb (GSimpleAction *action,
GVariant *parameter,
Expand Down Expand Up @@ -208,6 +219,7 @@ create_menu_model (TildaContextMenu * context_menu)
GMenu *toggle_section = g_menu_new ();
g_menu_append (toggle_section, _("_Toggle Fullscreen"), "window.fullscreen");
g_menu_append (toggle_section, _("_Toggle Searchbar"), "window.searchbar");
g_menu_append (toggle_section, _("_Toggle Pinned Mode"), "window.pin");
g_menu_append_section (menu, NULL, G_MENU_MODEL (toggle_section));

// preferences section
Expand Down Expand Up @@ -259,6 +271,7 @@ tilda_context_menu_popup (tilda_window *tw, tilda_term *tt, const char * match,
{ .name="close-tab", menu_close_tab_cb },
{ .name="fullscreen", menu_fullscreen_cb },
{ .name="searchbar", menu_searchbar_cb },
{ .name="pin", menu_pin_cb },
{ .name="preferences", menu_preferences_cb },
{ .name="quit", menu_quit_cb }
};
Expand Down
34 changes: 34 additions & 0 deletions src/tilda-keybinding.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const Keybinding common_bindings[] = {
{"Toggle Fullscreen", "fullscreen_key"},
{"Toggle Transparency", "toggle_transparency_key"},
{"Toggle Searchbar", "toggle_searchbar_key"},
{"Toggle Pin", "pin_key"},
{NULL, NULL}
};

Expand Down Expand Up @@ -125,6 +126,11 @@ validate_pulldown_keybinding (const gchar* accel,
const gchar* message,
gboolean allow_empty_pull_shortcut);

static gboolean
validate_pin_keybinding (const gchar* accel,
tilda_window* tw,
const gchar* message);

static gboolean
validate_keybinding (const gchar* accel,
tilda_window *tw,
Expand Down Expand Up @@ -505,6 +511,12 @@ validate_keybindings (TildaKeybindingTreeView *keybindings,
if (!validate_pulldown_keybinding (shortcut, tw, message, allow_empty_pull_shortcut))
return FALSE;
}
else if (0 == g_strcmp0 ("pin_key", config_name)) {
const char *message = _ ("The keybinding you chose for \"Toggle Pin\" is invalid. Please choose another.");

if (!validate_pin_keybinding (shortcut, tw, message))
return FALSE;
}
else {
gchar * message = g_strdup_printf (
_ ("The keybinding you chose for \"%s\" is invalid. Please choose another."),
Expand Down Expand Up @@ -556,6 +568,28 @@ validate_pulldown_keybinding (const gchar* accel,
}
}

static gboolean
validate_pin_keybinding (const gchar* accel,
tilda_window* tw,
const gchar* message)
{
if (strcmp(accel, "NULL") == 0) return TRUE;

/* Try to grab the key. This is a good way to validate it :) */
gboolean key_is_valid = tilda_keygrabber_bind_pin (accel, tw);

if (key_is_valid)
return TRUE;
else
{
GtkWindow *window = GTK_WINDOW(tw->wizard_window);

tilda_keybinding_show_invalid_keybinding_dialog (window, message);

return FALSE;
}
}

static gboolean
validate_keybinding (const gchar* accel,
tilda_window *tw,
Expand Down
3 changes: 3 additions & 0 deletions src/tilda.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ int main (int argc, char *argv[])
message);
wizard (&tw);
}

/* Bind the pin key globally */
tilda_keygrabber_bind_pin (config_getstr ("pin_key"), &tw);
}
}

Expand Down
Loading