From 097e8e41728ecbcad5c97e1a95cd106e2115aa9d Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 13 Dec 2007 13:59:46 +0100 Subject: [PATCH] Add uicb_screen_focus to switch to a specified screen. --- awesomerc | 6 ++++-- screen.c | 40 +++++++++++++++++++++------------------- screen.h | 3 +-- uicb.c | 3 +-- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/awesomerc b/awesomerc index 543c1eaf..381f4d51 100644 --- a/awesomerc +++ b/awesomerc @@ -181,13 +181,15 @@ keys { modkey = {"Mod4", "Control"} key = "j" - command = "screen_focusnext" + command = "screen_focus" + arg = "+1" } key { modkey = {"Mod4", "Control"} key = "k" - command = "screen_focusprev" + command = "screen_focus" + arg = "-1" } key { diff --git a/screen.c b/screen.c index cbd9cf64..816183cc 100644 --- a/screen.c +++ b/screen.c @@ -241,30 +241,32 @@ move_mouse_pointer_to_screen(Display *disp, int screen) XWarpPointer(disp, None, RootWindow(disp, screen), 0, 0, 0, 0, 0, 0); } + +/** Switch focus to a specified screen + * \param awesomeconf awesome config ref + * \param arg screen number + * \ingroup ui_callback + */ void -uicb_screen_focusnext(awesome_config * awesomeconf, - int screen, - const char *arg __attribute__ ((unused))) +uicb_screen_focus(awesome_config *awesomeconf, int screen, const char *arg) { - int next_screen = screen + 1 >= get_screen_count(awesomeconf->display) ? 0 : screen + 1; - Client *sel = get_current_tag(awesomeconf->screens[next_screen].tags, - awesomeconf->screens[next_screen].ntags)->client_sel; + int new_screen, numscreens = get_screen_count(awesomeconf->display); - focus(sel, True, awesomeconf, next_screen - screen); - move_mouse_pointer_to_screen(awesomeconf->display, next_screen); -} + if(arg) + new_screen = compute_new_value_from_arg(arg, screen); + else + new_screen = screen + 1; -void -uicb_screen_focusprev(awesome_config * awesomeconf, - int screen, - const char *arg __attribute__ ((unused))) -{ - int prev_screen = screen - 1 < 0 ? get_screen_count(awesomeconf->display) - 1 : screen - 1; - Client *sel = get_current_tag(awesomeconf->screens[prev_screen].tags, - awesomeconf->screens[prev_screen].ntags)->client_sel; + if (new_screen < 0) + new_screen = numscreens - 1; + if (new_screen > (numscreens - 1)) + new_screen = 0; - focus(sel, True, awesomeconf, prev_screen - screen); - move_mouse_pointer_to_screen(awesomeconf->display, prev_screen); + focus(get_current_tag(awesomeconf->screens[new_screen].tags, + awesomeconf->screens[new_screen].ntags)->client_sel, + True, awesomeconf, new_screen); + + move_mouse_pointer_to_screen(awesomeconf->display, new_screen); } /** Move client to a virtual screen (if Xinerama is active) diff --git a/screen.h b/screen.h index b62d2373..5814516e 100644 --- a/screen.h +++ b/screen.h @@ -35,8 +35,7 @@ int get_screen_count(Display *); int get_phys_screen(Display *, int); void move_client_to_screen(Client *, awesome_config *, int, Bool); -UICB_PROTO(uicb_screen_focusnext); -UICB_PROTO(uicb_screen_focusprev); +UICB_PROTO(uicb_screen_focus); UICB_PROTO(uicb_client_movetoscreen); #endif diff --git a/uicb.c b/uicb.c index 779d2534..48576923 100644 --- a/uicb.c +++ b/uicb.c @@ -62,8 +62,7 @@ const NameFuncLink UicbList[] = { {"tag_setnmaster", uicb_tag_setnmaster}, {"tag_setncol", uicb_tag_setncol}, /* screen.c */ - {"screen_focusnext", uicb_screen_focusnext}, - {"screen_focusprev", uicb_screen_focusprev}, + {"screen_focus", uicb_screen_focus}, {"client_movetoscreen", uicb_client_movetoscreen}, /* awesome.c */ {"quit", uicb_quit},