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

[PATCH] Default to toggle for on|off|toggle commands



Attached is a patch so commands with on|off|toggle arguments
(currently fullscreen/pseudotile/floating) default to "toggle" if no
argument is given.

For fullscreen this was already mentioned in the manpage, but not
implemented.

While I was at it, I also fixed some inconsistent formatting in the
manpage regarding these options.

Florian

-- 
() ascii ribbon campaign - stop html mail    www.asciiribbon.org
/\ www.the-compiler.org  | I love long mails http://email.is-not-s.ms/
About all some men accomplish in life is to send a son to Harvard. 
From 67d7239c15878ea24fa6d66c81175cc5719f0caa Mon Sep 17 00:00:00 2001
From: Florian Bruhin <git _at_ the _minus_ compiler _dot_ org>
Date: Sat, 17 Nov 2012 23:35:51 +0100
Subject: [PATCH] Default to "toggle" for on|off|toggle commands

For "fullscreen" it already was in the manpage, but not in the code.
---
 doc/herbstluftwm.txt | 16 +++++++++-------
 src/clientlist.c     |  6 ++----
 src/tag.c            |  5 +----
 3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
index 53c5fa5..a4f67f9 100644
--- a/doc/herbstluftwm.txt
+++ b/doc/herbstluftwm.txt
@@ -575,11 +575,11 @@ tag_status ['MONITOR']::
 WARNING: If you use a tab in one of the tag names, then tag_status is probably
 quite useless for you.
 
-floating [['TAG'] on|off|toggle|status]::
+floating [['TAG'] *on*|*off*|*toggle*|*status*]::
     Changes the current tag to floating/tiling mode on specified 'TAG' or prints
     it current status. If no 'TAG' is given, current tag is used. If no argument
-    is given, floating mode is toggled. If status is given, then on or off is
-    printed, depending of the floating state on 'TAG'.
+    is given, floating mode is toggled. If status is given, then *on* or *off*
+    is printed, depending of the floating state on 'TAG'.
 
 rule [\[--]'FLAG'|\[--]'CONDITION'|\[--]'CONSEQUENCE' ...]::
     Defines a rule which will be applied to all new clients. Its behaviour is
@@ -589,14 +589,16 @@ unrule *--all*|*-F*::
     If --all or -F is passed, then all rules are removed.
     (It is not possible yet to remove certain rules)
 
-fullscreen *on*|*off*|*toggle*::
-    Sets or toggles the fullscreen state of the focused client.
+fullscreen [*on*|*off*|*toggle*]::
+    Sets or toggles the fullscreen state of the focused client. If no argument
+    is given, fullscreen mode is toggled.
 
-pseudotile *on*|*off*|*toggle*::
+pseudotile [*on*|*off*|*toggle*]::
     Sets or toggles the pseudotile state of the focused client. If a client is
     pseudotiled, then in tiling mode the client is only moved but not resized -
     the client size will stay the floating size. The only reason to resize the
-    client is to ensure, that it fits into its tile.
+    client is to ensure, that it fits into its tile. If no argument is given,
+    fullscreen mode is toggled.
 
 getenv 'NAME'::
     Gets the value of the environment variable 'NAME'.
diff --git a/src/clientlist.c b/src/clientlist.c
index 9143088..6afd7b5 100644
--- a/src/clientlist.c
+++ b/src/clientlist.c
@@ -665,9 +665,7 @@ void client_set_pseudotile(HSClient* client, bool state) {
 }
 
 int client_set_property_command(int argc, char** argv) {
-    if (argc < 2) {
-        return HERBST_INVALID_ARGUMENT;
-    }
+    char* action = (argc > 1) ? argv[1] : "toggle";
 
     HSClient* client = get_current_client();
     if (!client) {
@@ -696,7 +694,7 @@ int client_set_property_command(int argc, char** argv) {
     }
 
     // if found, then change it
-    bool state = string_to_bool(argv[1], *(properties[i].value));
+    bool state = string_to_bool(action, *(properties[i].value));
     properties[i].func(client, state);
     return 0;
 }
diff --git a/src/tag.c b/src/tag.c
index 65b85f7..8c2de3c 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -228,10 +228,7 @@ int tag_remove_command(int argc, char** argv) {
 int tag_set_floating_command(int argc, char** argv, GString* output) {
     // usage: floating [[tag] on|off|toggle]
     HSTag* tag = get_current_monitor()->tag;
-    if (argc < 2) {
-        return HERBST_INVALID_ARGUMENT;
-    }
-    char* action = argv[1];
+    char* action = (argc > 1) ? argv[1] : "toggle";
     if (argc >= 3) {
         // if a tag is specified
         tag = find_tag(argv[1]);
-- 
1.8.0

Attachment: pgpW4GX67iJU9.pgp
Description: PGP signature