| 1 |
#! perl |
| 2 |
|
| 3 |
#:META:RESOURCE:%.hotkey:string:activation hotkey keysym |
| 4 |
|
| 5 |
=head1 NAME |
| 6 |
|
| 7 |
kuake - kuake-like hotkey terminal |
| 8 |
|
| 9 |
=head1 EXAMPLES |
| 10 |
|
| 11 |
urxvt -kuake-hotkey F10 |
| 12 |
|
| 13 |
URxvt.kuake.hotkey: F10 |
| 14 |
|
| 15 |
=head1 DESCRIPTION |
| 16 |
|
| 17 |
A very primitive quake-console-like extension. It was inspired by a |
| 18 |
description of how the programs C<kuake> and C<yakuake> work: Whenever the |
| 19 |
user presses a global accelerator key (by default C<F10>), the terminal |
| 20 |
will show or hide itself. Another press of the accelerator key will hide |
| 21 |
or show it again. |
| 22 |
|
| 23 |
Initially, the window will not be shown when using this extension. |
| 24 |
|
| 25 |
This is useful if you need a single terminal that is not using any desktop |
| 26 |
space most of the time but is quickly available at the press of a key. |
| 27 |
|
| 28 |
The accelerator key is grabbed regardless of any modifiers, so this |
| 29 |
extension will actually grab a physical key just for this function. |
| 30 |
|
| 31 |
If you want a quake-like animation, tell your window manager to do so |
| 32 |
(fvwm can do it). |
| 33 |
|
| 34 |
=cut |
| 35 |
|
| 36 |
sub on_start { |
| 37 |
my ($self) = @_; |
| 38 |
|
| 39 |
$self->{key} = $self->{argv}[0] || $self->x_resource ("%.hotkey") || "F10"; |
| 40 |
|
| 41 |
$self->{keysym} = $self->XStringToKeysym ($self->{key}) |
| 42 |
or urxvt::fatal "cannot convert requested kuake wake-up key '$self->{key}' to keysym, unable to continue.\n"; |
| 43 |
|
| 44 |
$self->{keycode} = $self->XKeysymToKeycode ($self->{keysym}) |
| 45 |
or urxvt::fatal "cannot convert requested kuake wake-up key '$self->{key}' to keycode, unable to continue.\n"; |
| 46 |
|
| 47 |
$self->XGrabKey ($self->{keycode}, urxvt::AnyModifier, $self->DefaultRootWindow); |
| 48 |
|
| 49 |
$self->XUnmapWindow ($self->parent); |
| 50 |
|
| 51 |
$self->{unmap_me} = 1; |
| 52 |
|
| 53 |
() |
| 54 |
} |
| 55 |
|
| 56 |
sub on_map_notify { |
| 57 |
my ($self) = @_; |
| 58 |
|
| 59 |
# suppress initial map event |
| 60 |
$self->XUnmapWindow ($self->parent) |
| 61 |
if delete $self->{unmap_me}; |
| 62 |
|
| 63 |
() |
| 64 |
} |
| 65 |
|
| 66 |
sub on_root_event { |
| 67 |
my ($self, $event) = @_; |
| 68 |
|
| 69 |
return unless $event->{type} == urxvt::KeyPress && $event->{keycode} == $self->{keycode}; |
| 70 |
|
| 71 |
$self->mapped |
| 72 |
? $self->XUnmapWindow ($self->parent) |
| 73 |
: $self->XMapWindow ($self->parent); |
| 74 |
|
| 75 |
1 |
| 76 |
} |
| 77 |
|
| 78 |
sub on_destroy { |
| 79 |
my ($self) = @_; |
| 80 |
|
| 81 |
$self->XUngrabKey ($self->XKeysymToKeycode ($self->{keysym}), 0, $self->DefaultRootWindow) |
| 82 |
if $self->{keysym}; |
| 83 |
|
| 84 |
() |
| 85 |
} |