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