diff options
author | Florian Bruhin <git@the-compiler.org> | 2012-11-28 00:11:32 +0100 |
---|---|---|
committer | Thorsten Wißmann <edu@thorsten-wissmann.de> | 2012-12-24 18:36:52 +0100 |
commit | e529408b8813bf8a9b1e2dfbeeb73b94e738795b (patch) | |
tree | 49a505e44d40e03041bfbd1b206132a2a93599e5 /src | |
parent | 8b274bb4588304bd586b392f97c4fa4f70fcee57 (diff) |
Add new command rename_monitor
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 1 | ||||
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/monitor.c | 38 | ||||
-rw-r--r-- | src/monitor.h | 1 |
4 files changed, 41 insertions, 0 deletions
diff --git a/src/command.c b/src/command.c index cb93c937..c2bf37f7 100644 --- a/src/command.c +++ b/src/command.c @@ -99,6 +99,7 @@ struct { { "unlock_tag", 2, no_completion }, { "detect_monitors",1, no_completion }, { "add_monitor", 7, no_completion }, + { "rename_monitor", 3, no_completion }, { "remove_monitor", 2, no_completion }, { "move_monitor", 7, no_completion }, { "raise_monitor", 2, no_completion }, @@ -138,6 +138,7 @@ CommandBinding g_commands[] = { CMD_BIND( "raise_monitor", monitor_raise_command), CMD_BIND( "remove_monitor", remove_monitor_command), CMD_BIND( "move_monitor", move_monitor_command), + CMD_BIND( "rename_monitor", rename_monitor_command), CMD_BIND( "monitor_rect", monitor_rect_command), CMD_BIND( "pad", monitor_set_pad_command), CMD_BIND( "raise", raise_command), diff --git a/src/monitor.c b/src/monitor.c index 7c7f41c0..0fc8cbf1 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -531,6 +531,44 @@ int move_monitor_command(int argc, char** argv, GString* output) { return 0; } +int rename_monitor_command(int argc, char** argv, GString* output) { + if (argc < 3) { + return HERBST_NEED_MORE_ARGS; + } + HSMonitor* mon = string_to_monitor(argv[1]); + if (mon == NULL) { + g_string_append_printf(output, + "%s: Monitor \"%s\" not found!\n", argv[0], argv[1]); + return HERBST_INVALID_ARGUMENT; + } + if (isdigit(argv[2][0])) { + g_string_append_printf(output, + "%s: The monitor name may not start with a number\n", argv[0]); + return HERBST_INVALID_ARGUMENT; + } else if (!strcmp("", argv[2])) { + // empty name -> clear name + if (mon->name != NULL) { + g_string_free(mon->name, true); + mon->name = NULL; + } + return 0; + } + if (find_monitor_by_name(argv[2])) { + g_string_append_printf(output, + "%s: A monitor with the same name already exists\n", argv[0]); + return HERBST_INVALID_ARGUMENT; + } + if (mon->name == NULL) { + // not named before + GString* name = g_string_new(argv[2]); + mon->name = name; + } else { + // already named + g_string_assign(mon->name, argv[2]); + } + return 0; +} + int monitor_rect_command(int argc, char** argv, GString* output) { // usage: monitor_rect [[-p] INDEX] char* monitor_str = NULL; diff --git a/src/monitor.h b/src/monitor.h index bd4e6c59..6fc25af3 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -70,6 +70,7 @@ int set_monitor_rects_command(int argc, char** argv, GString* output); int disjoin_rects_command(int argc, char** argv, GString* output); int set_monitor_rects(XRectangle* templates, size_t count); int move_monitor_command(int argc, char** argv, GString* output); +int rename_monitor_command(int argc, char** argv, GString* output); int monitor_rect_command(int argc, char** argv, GString* output); HSMonitor* get_current_monitor(); int monitor_count(); |