From 72c0d4962dd01f63adc59b966ea206ebdd4c3f9b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 14 Nov 2012 19:14:39 +0100 Subject: Print error when frame neighbours are missing --- src/layout.c | 17 +++++++++++++---- src/layout.h | 4 ++-- src/main.c | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/layout.c b/src/layout.c index 0ef9d19d..259d8889 100644 --- a/src/layout.c +++ b/src/layout.c @@ -1207,8 +1207,9 @@ int frame_change_fraction_command(int argc, char** argv, GString* output) { } neighbour = frame_neighbour(g_cur_frame, direction); if (!neighbour) { - // nothing to do - return 0; + g_string_append_printf(output, + "%s: No neighbour found!", argv[0]); + return HERBST_FORBIDDEN; } } HSFrame* parent = neighbour->parent; @@ -1326,7 +1327,7 @@ int frame_inner_neighbour_index(HSFrame* frame, char direction) { return index; } -int frame_focus_command(int argc, char** argv) { +int frame_focus_command(int argc, char** argv, GString* output) { // usage: focus [-e|-i] left|right|up|down if (argc < 2) return HERBST_NEED_MORE_ARGS; if (!g_cur_frame) { @@ -1361,12 +1362,16 @@ int frame_focus_command(int argc, char** argv) { // change focus if possible frame_focus_recursive(parent); monitor_apply_layout(get_current_monitor()); + } else { + g_string_append_printf(output, + "%s: No neighbour found!", argv[0]); + return HERBST_FORBIDDEN; } } return 0; } -int frame_move_window_command(int argc, char** argv) { +int frame_move_window_command(int argc, char** argv, GString* output) { // usage: move left|right|up|down if (argc < 2) return HERBST_NEED_MORE_ARGS; if (!g_cur_frame) { @@ -1429,6 +1434,10 @@ int frame_move_window_command(int argc, char** argv) { } // layout was changed, so update it monitor_apply_layout(get_current_monitor()); + } else { + g_string_append_printf(output, + "%s: No neighbour found!", argv[0]); + return HERBST_FORBIDDEN; } } return 0; diff --git a/src/layout.h b/src/layout.h index ebb2882d..f09a07f0 100644 --- a/src/layout.h +++ b/src/layout.h @@ -138,7 +138,7 @@ void frame_unfocus(); // unfocus currently focused window // returns the neighbour or NULL if there is no one HSFrame* frame_neighbour(HSFrame* frame, char direction); int frame_inner_neighbour_index(HSFrame* frame, char direction); -int frame_focus_command(int argc, char** argv); +int frame_focus_command(int argc, char** argv, GString* output); // follow selection to leave and focus this frame int frame_focus_recursive(HSFrame* frame); @@ -163,7 +163,7 @@ Window frame_focused_window(HSFrame* frame); bool frame_focus_window(HSFrame* frame, Window win); bool focus_window(Window win, bool switch_tag, bool switch_monitor); // moves a window to an other frame -int frame_move_window_command(int argc, char** argv); +int frame_move_window_command(int argc, char** argv, GString* output); /// removes the current frame int frame_remove_command(int argc, char** argv); int close_or_remove_command(int argc, char** argv); diff --git a/src/main.c b/src/main.c index b6ccb082..6bc4260d 100644 --- a/src/main.c +++ b/src/main.c @@ -109,8 +109,8 @@ CommandBinding g_commands[] = { CMD_BIND_NO_OUTPUT( "close_or_remove",close_or_remove_command), CMD_BIND( "split", frame_split_command), CMD_BIND( "resize", frame_change_fraction_command), - CMD_BIND_NO_OUTPUT( "focus", frame_focus_command), - CMD_BIND_NO_OUTPUT( "shift", frame_move_window_command), + CMD_BIND( "focus", frame_focus_command), + CMD_BIND( "shift", frame_move_window_command), CMD_BIND_NO_OUTPUT( "remove", frame_remove_command), CMD_BIND( "set", settings_set_command), CMD_BIND( "toggle", settings_toggle), -- cgit v1.2.3