[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] New command: use_last



Aaaaand another patch, since some people in IRC wanted an easy way to
do this.

This patch implements an use_last command which jumps to the tag which
was focused before switching to the tag which is focused now.

It applies on top of my previous patch, but applying it to git HEAD
only gives me a small and easy to resolve merge conflict in NEWS.

~Florian

-- 
O< ascii ribbon campaign - stop html mail    www.asciiribbon.org
   www.the-compiler.org  | I love long mails http://email.is-not-s.ms/
Just when you thought you were winning the rat race, along comes a faster 
rat!! 
>From 511397e10398ae645d8f024dd7199250d3f3ad22 Mon Sep 17 00:00:00 2001
From: Florian Bruhin <git _at_ the _minus_ compiler _dot_ org>
Date: Wed, 31 Oct 2012 11:52:59 +0100
Subject: [PATCH] new command: use_last

---
 NEWS                 |  1 +
 doc/herbstluftwm.txt |  4 ++++
 src/command.c        |  1 +
 src/main.c           |  1 +
 src/monitor.c        | 18 ++++++++++++++++--
 src/monitor.h        |  6 ++++--
 6 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 16ea50b..7118214 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,7 @@ Changes:
     * set the urgent flag on _NET_WM_STATE_DEMANDS_ATTENTION
     * clear the urgent flag on window focus
     * new command: list_padding
+    * new command: use_last
 
 Release: 0.4.1 on 2012-08-30
 ----------------------------
diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
index bf97816..5b93851 100644
--- a/doc/herbstluftwm.txt
+++ b/doc/herbstluftwm.txt
@@ -388,6 +388,10 @@ add 'TAG'::
 use 'TAG'::
     Switches the focused monitor to specified 'TAG'.
 
+use_last::
+    Switches the focused monitor to the tag which was viewed last (before
+    switching to the tag viewed now)
+
 use_index 'INDEX' [*--skip-visible*]::
     Switches the focused monitor to the 'TAG' with the specified 'INDEX'. If
     'INDEX' starts with +++ or +-+, then 'INDEX' is treated relative to the
diff --git a/src/command.c b/src/command.c
index 27bba8f..1c15b8e 100644
--- a/src/command.c
+++ b/src/command.c
@@ -103,6 +103,7 @@ struct {
     { "unrule",         2,  no_completion },
     { "use",            2,  no_completion },
     { "use_index",      3,  no_completion },
+    { "use_last",       0,  no_completion },
     { "add",            2,  no_completion },
     { "get",            2,  no_completion },
     { "toggle",         2,  no_completion },
diff --git a/src/main.c b/src/main.c
index e6b0811..f7b577f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -117,6 +117,7 @@ CommandBinding g_commands[] = {
     CMD_BIND_NO_OUTPUT(   "add",            tag_add_command),
     CMD_BIND_NO_OUTPUT(   "use",            monitor_set_tag_command),
     CMD_BIND_NO_OUTPUT(   "use_index",      monitor_set_tag_by_index_command),
+    CMD_BIND_NO_OUTPUT(   "use_last",       monitor_set_last_tag_command),
     CMD_BIND_NO_OUTPUT(   "jumpto",         jumpto_command),
     CMD_BIND(             "floating",       tag_set_floating_command),
     CMD_BIND_NO_OUTPUT(   "fullscreen",     client_set_property_command),
diff --git a/src/monitor.c b/src/monitor.c
index d815329..aa7f076 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -320,6 +320,7 @@ HSMonitor* add_monitor(XRectangle rect, HSTag* tag) {
     HSMonitor* m = g_new0(HSMonitor, 1);
     m->rect = rect;
     m->tag = tag;
+    m->last_tag = NULL;
     m->mouse.x = 0;
     m->mouse.y = 0;
     m->dirty = true;
@@ -592,7 +593,7 @@ void monitor_set_tag(HSMonitor* monitor, HSTag* tag) {
         }
         return;
     }
-    HSTag* old_tag = monitor->tag;
+    monitor->last_tag = monitor->tag;
     // 1. show new tag
     monitor->tag = tag;
     // first reset focus and arrange windows
@@ -607,7 +608,7 @@ void monitor_set_tag(HSMonitor* monitor, HSTag* tag) {
         frame_update_frame_window_visibility(monitor->tag->frame);
     }
     // 2. hide old tag
-    frame_hide_recursive(old_tag->frame);
+    frame_hide_recursive(monitor->last_tag->frame);
     // focus window just has been shown
     // focus again to give input focus
     frame_focus_recursive(tag->frame);
@@ -649,6 +650,19 @@ int monitor_set_tag_by_index_command(int argc, char** argv) {
     return 0;
 }
 
+int monitor_set_last_tag_command(int argc, char** argv) {
+    (void) argc;
+    (void) argv;
+    HSMonitor* monitor = get_current_monitor();
+    HSTag* tag = monitor->last_tag;
+    if (monitor && tag) {
+        monitor_set_tag(monitor, tag);
+        return 0;
+    } else {
+        return HERBST_INVALID_ARGUMENT;
+    }
+}
+
 int monitor_focus_command(int argc, char** argv) {
     if (argc < 2) {
         return HERBST_INVALID_ARGUMENT;
diff --git a/src/monitor.h b/src/monitor.h
index 53b8b3e..fbd368b 100644
--- a/src/monitor.h
+++ b/src/monitor.h
@@ -19,8 +19,9 @@ struct HSSlice;
 struct HSStack;
 
 typedef struct HSMonitor {
-    struct HSTag*      tag;    // currently viewed tag
-    struct HSSlice*    slice;  // slice in the monitor stack
+    struct HSTag*      tag;      // currently viewed tag
+    struct HSTag*      last_tag; // tag which was viewed last
+    struct HSSlice*    slice;    // slice in the monitor stack
     int         pad_up;
     int         pad_right;
     int         pad_down;
@@ -72,6 +73,7 @@ void monitor_set_tag(HSMonitor* monitor, struct HSTag* tag);
 int monitor_set_pad_command(int argc, char** argv);
 int monitor_set_tag_command(int argc, char** argv);
 int monitor_set_tag_by_index_command(int argc, char** argv);
+int monitor_set_last_tag_command(int argc, char** argv);
 int monitors_lock_command(int argc, char** argv);
 int monitors_unlock_command(int argc, char** argv);
 void monitors_lock_changed();
-- 
1.8.0