Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
Show key equivalent in window title.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-seddon committed Nov 18, 2014
1 parent 851bf30 commit 7cff302
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
2 changes: 2 additions & 0 deletions man/quartz-wm.man
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/frame.h
Expand Up @@ -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);
Expand Down
22 changes: 19 additions & 3 deletions src/frame.m
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/main.m
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -902,6 +909,8 @@ static void signal_handler_cb(CFRunLoopObserverRef observer,
[w do_unshade:CurrentTime];
[w update_net_wm_action_property];
}

[w decorate];
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/quartz-wm.h
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/x-window.m
Expand Up @@ -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;
Expand Down

0 comments on commit 7cff302

Please sign in to comment.