From 7cff302bf1997cfc1f5e5a8ced92ae47d1bc872d Mon Sep 17 00:00:00 2001 From: Tom Seddon Date: Mon, 17 Nov 2014 03:30:02 +0000 Subject: [PATCH] Show key equivalent in window title. --- man/quartz-wm.man | 2 ++ src/frame.h | 3 ++- src/frame.m | 22 +++++++++++++++++++--- src/main.m | 9 +++++++++ src/quartz-wm.h | 4 +++- src/x-window.m | 2 +- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/man/quartz-wm.man b/man/quartz-wm.man index a723b24..3184440 100644 --- a/man/quartz-wm.man +++ b/man/quartz-wm.man @@ -84,6 +84,8 @@ Automatically quit Set the timeout for the auto-quit feature. If wm_auto_quit is true, quartz-wm will wait this many seconds before attempting to shutdown. If another window is created in that time, quartz-wm will not shutdown. +.It defaults write __bundle_id_prefix__.X11 wm_show_shortcut -bool true +Show each window's key equivalent, if it has one, in its title bar. .El .Sh LOGGING .Pp diff --git a/src/frame.h b/src/frame.h index 717df0a..d382fc5 100644 --- a/src/frame.h +++ b/src/frame.h @@ -69,7 +69,8 @@ typedef enum xp_frame_attr_enum xp_frame_attr; extern void draw_frame (int screen, Window xwindow_id, X11Rect outer_r, X11Rect inner_r, xp_frame_class class, - xp_frame_attr attr, CFStringRef title); + xp_frame_attr attr, CFStringRef title, + int shortcut_index); extern int frame_titlebar_height (xp_frame_class class); extern X11Rect frame_tracking_rect (X11Rect outer_r, X11Rect inner_r, xp_frame_class class); diff --git a/src/frame.m b/src/frame.m index dfbbbf4..b3b1009 100644 --- a/src/frame.m +++ b/src/frame.m @@ -43,10 +43,24 @@ void draw_frame (int screen, Window xwindow_id, X11Rect outer_r, X11Rect inner_r, - xp_frame_class class, xp_frame_attr attr, CFStringRef title) + xp_frame_class class, xp_frame_attr attr, CFStringRef title, + int shortcut_index) { unsigned char title_bytes[512]; CFIndex title_length; + size_t prefix_length = 0; + + if (show_shortcut && enable_key_equivalents) + { + if (shortcut_index > 0) + { + // E2 8C 98 = PLACE OF INTEREST SIGN + snprintf((char *)title_bytes, sizeof title_bytes, "\xE2\x8C\x98%d%s", + shortcut_index, title == NULL ? "" : " - "); + + prefix_length = strlen((char *)title_bytes); + } + } if (title == NULL) title_length = 0; @@ -55,11 +69,13 @@ /* FIXME: kind of lame */ CFStringGetBytes (title, CFRangeMake (0, CFStringGetLength (title)), kCFStringEncodingUTF8, 0, - FALSE, title_bytes, - sizeof (title_bytes), + FALSE, title_bytes + prefix_length, + sizeof (title_bytes) - prefix_length, &title_length); } + title_length += prefix_length; + DB("id: 0x%ld outer_r: (%d,%d %dx%d) inner_r: (%d,%d %dx%d) class: 0x%d attr: 0x%d title: %s", xwindow_id, outer_r.x, outer_r.y, outer_r.width, outer_r.height, inner_r.x, inner_r.y, inner_r.width, inner_r.height, class, attr, diff --git a/src/main.m b/src/main.m index d2f5603..62a190f 100644 --- a/src/main.m +++ b/src/main.m @@ -69,6 +69,11 @@ BOOL auto_quit = NO; int auto_quit_timeout = 3; /* Seconds to wait before auto-quiting */ BOOL minimize_on_double_click = YES; +BOOL show_shortcut = NO; +BOOL enable_key_equivalents = YES; /* quartz-wm doesn't use this per + * se, but it queries it so it knows + * not to display shortcuts when key + * equivalents are disabled. */ aslclient aslc; @@ -876,6 +881,8 @@ static inline void prefs_read(void) { auto_quit = prefs_get_bool (CFSTR (PREFS_AUTO_QUIT), auto_quit); auto_quit_timeout = prefs_get_int (CFSTR (PREFS_AUTO_QUIT_TIMEOUT), auto_quit_timeout); minimize_on_double_click = prefs_get_bool (CFSTR(PREFS_MINIMIZE_ON_DOUBLE_CLICK), minimize_on_double_click); + show_shortcut = prefs_get_bool (CFSTR (PREFS_SHOW_SHORTCUT), show_shortcut); + enable_key_equivalents = prefs_get_bool (CFSTR (PREFS_ENABLE_KEY_EQUIVALENTS), enable_key_equivalents); } static void signal_handler_cb(CFRunLoopObserverRef observer, @@ -902,6 +909,8 @@ static void signal_handler_cb(CFRunLoopObserverRef observer, [w do_unshade:CurrentTime]; [w update_net_wm_action_property]; } + + [w decorate]; } } } diff --git a/src/quartz-wm.h b/src/quartz-wm.h index f98889b..068788a 100644 --- a/src/quartz-wm.h +++ b/src/quartz-wm.h @@ -77,10 +77,12 @@ #define PREFS_AUTO_QUIT "wm_auto_quit" #define PREFS_AUTO_QUIT_TIMEOUT "wm_auto_quit_timeout" #define PREFS_MINIMIZE_ON_DOUBLE_CLICK "AppleMiniaturizeOnDoubleClick" +#define PREFS_SHOW_SHORTCUT "wm_show_shortcut" +#define PREFS_ENABLE_KEY_EQUIVALENTS "enable_key_equivalents" /* from main.m */ extern x_list *screen_list; -extern BOOL focus_follows_mouse, focus_click_through, limit_window_size, focus_on_new_window, window_shading, rootless, auto_quit, minimize_on_double_click; +extern BOOL focus_follows_mouse, focus_click_through, limit_window_size, focus_on_new_window, window_shading, rootless, auto_quit, minimize_on_double_click, show_shortcut, enable_key_equivalents; extern int auto_quit_timeout; extern void x_grab_server (Bool do_sync); extern void x_ungrab_server (void); diff --git a/src/x-window.m b/src/x-window.m index e3b9066..69822ca 100644 --- a/src/x-window.m +++ b/src/x-window.m @@ -1043,7 +1043,7 @@ - (void) decorate_rect:(X11Rect)or _drawn_frame_decor = [self get_xp_frame_class] & XP_FRAME_CLASS_DECOR_MASK; draw_frame (_screen->_id, _frame_id, or, ir, [self get_xp_frame_class], - frame_attr, (CFStringRef) [self title]); + frame_attr, (CFStringRef) [self title], _shortcut_index); _decorated = YES; _pending_decorate = NO;