Hi everyone,
I decided to implement a couple of focus-related Yakuake behaviours in
the kuake extension ("hide on loss of focus" and "focus rather than
hiding if visible but unfocused") and I've attached both the changes and
their new documentation as a patch.
I couldn't find any way to cause URxvt to raise itself via the Perl API,
so the latter feature uses the wmctrl command (via File::Which) if
available and, if either of those dependencies is missing, falls back to
hiding and showing the window in rapid succession.
I've tested all code paths, though I had to take the File::Which
author's word that it will return "undef" on failure.
Legal disclaimer: Do with it as you will. Print it out and line a
birdcage if the mood strikes you.
--
Stephan Sokolow
Note: My e-mail address IS valid. It's a little trick I use to fool
"smarter" spambots and remind friends and family to use the custom
aliases I gave them.
diff -ur rxvt-unicode/src/perl/kuake rxvt-unicode.new/src/perl/kuake
--- rxvt-unicode/src/perl/kuake 2006-07-06 19:48:11.000000000 -0400
+++ rxvt-unicode.new/src/perl/kuake 2011-10-01 12:27:23.000000000 -0400
@@ -1,9 +1,13 @@
#! perl
+my $has_which = eval "use File::Which; 1";
+
sub on_start {
my ($self) = @_;
$self->{key} = $self->{argv}[0] || "F10";
+ $self->{hide_on_lose_focus} = $self->x_resource('kuake.hideOnLoseFocus') || 0;
+ $self->{toggle_focuses_if_visible} = $self->x_resource('kuake.toggleFocusesIfVisible') || 0;
$self->{keysym} = $self->XStringToKeysym ($self->{key})
or urxvt::fatal "cannot convert requested kuake wake-up key '$self->{key}' to keysym, unable to continue.\n";
@@ -11,6 +15,8 @@
$self->{keycode} = $self->XKeysymToKeycode ($self->{keysym})
or urxvt::fatal "cannot convert requested kuake wake-up key '$self->{key}' to keycode, unable to continue.\n";
+ $self->{wmctrl_path} = $has_which ? which('wmctrl') : 0;
+
$self->XGrabKey ($self->{keycode}, urxvt::AnyModifier, $self->DefaultRootWindow);
$self->XUnmapWindow ($self->parent);
@@ -20,13 +26,20 @@
()
}
+sub on_focus_out {
+ my ($self) = @_;
+
+ $self->XUnmapWindow($self->parent)
+ if $self->{hide_on_lose_focus}
+}
+
sub on_map_notify {
my ($self) = @_;
# suppress initial map event
$self->XUnmapWindow ($self->parent)
if delete $self->{unmap_me};
-
+
()
}
@@ -35,9 +48,20 @@
return unless $event->{type} == urxvt::KeyPress && $event->{keycode} == $self->{keycode};
- $self->mapped
- ? $self->XUnmapWindow ($self->parent)
- : $self->XMapWindow ($self->parent);
+ if (not $self->focus and $self->mapped and $self->{toggle_focuses_if_visible}) {
+ if ($self->{wmctrl_path}) {
+ my $cmd = $self->{wmctrl_path} . " -i -a " . int($self->parent);
+ print($cmd);
+ `$cmd`;
+ } else {
+ $self->XUnmapWindow ($self->parent);
+ $self->XMapWindow ($self->parent);
+ }
+ } else {
+ $self->mapped
+ ? $self->XUnmapWindow ($self->parent)
+ : $self->XMapWindow ($self->parent);
+ }
1
}
@@ -50,3 +74,4 @@
()
}
+
diff -ur rxvt-unicode/src/urxvt.pm rxvt-unicode.new/src/urxvt.pm
--- rxvt-unicode/src/urxvt.pm 2011-08-19 19:08:35.000000000 -0400
+++ rxvt-unicode.new/src/urxvt.pm 2011-10-01 12:25:56.000000000 -0400
@@ -307,6 +307,20 @@
If you want a quake-like animation, tell your window manager to do so
(fvwm can do it).
+As with C<yakuake>, the extension can also be set to hide the terminal window
+on loss of focus or to focus the window if, when the accelerator key is
+pressed, the window is visible but unfocused.
+
+That behaviour is controlled via these two resources:
+
+ URxvt.kuake.hideOnLoseFocus: <boolean, default 0>
+ URxvt.kuake.toggleFocusesIfVisible: <boolean, default 0>
+
+When possible, the latter option uses the wmctrl utility to focus the URxvt
+window but, if the latter option is enabled and either the File::Which Perl
+module or the wmctrl utility are missing, rapidly hiding and then showing the
+window will be used as a fallback.
+
=item overlay-osc
This extension implements some OSC commands to display timed popups on the
_______________________________________________
rxvt-unicode mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/rxvt-unicode