1 |
#! perl |
2 |
|
3 |
#:META:RESOURCE:clickthrough:string:clickthrough disable/off/on |
4 |
|
5 |
=head1 NAME |
6 |
|
7 |
clickthrough - make window "transparent" with respect to input events |
8 |
|
9 |
=head1 DESCRIPTION |
10 |
|
11 |
This extension can toggle the terminal window between "normal" and |
12 |
"clickthrough" states. In the latter state, inoput events such as clicks |
13 |
will go "through" the window, as if it weren't there. This cna be used to |
14 |
put a (preferably partially transparent) window in front of other windows |
15 |
and let clicks and other events go through the underlying window. |
16 |
|
17 |
See L<https://shallowsky.com/blog/2017/Apr/06/> for an example. |
18 |
|
19 |
This extension is loaded automatically when the C<-clickthrough mode> |
20 |
command line argument is given, and operates in one of three modes: |
21 |
|
22 |
=over |
23 |
|
24 |
=item C<disable> (the default) |
25 |
|
26 |
In this mode, everything works normally andf the OSC sequence is not |
27 |
active. |
28 |
|
29 |
=item C<on> |
30 |
|
31 |
In this mode, events go through the window, and this can be toggled via an |
32 |
OSC sequence. |
33 |
|
34 |
=item C<off> |
35 |
|
36 |
In this mode, events act normally, but this can be toggled via an OSC |
37 |
sequence. |
38 |
|
39 |
=back |
40 |
|
41 |
=head2 OSC SEQUENCE |
42 |
|
43 |
When enabled, the OSC sequence C<< 777;clickthroughI<mode> >> can be used |
44 |
to change the clickthrough mode. Example, switch it on, and then switch it |
45 |
off again: |
46 |
|
47 |
printf '\033]777;clickthrough:on\007' |
48 |
printf '\033]777;clickthrough:off\007' |
49 |
|
50 |
=head2 BUGS |
51 |
|
52 |
For this to work as expected, your window manager needs to support shaped |
53 |
windows fully, but most only have partial support. The only window manager |
54 |
known that handles this correctly is openbox 3.7 (and partially 3.6). |
55 |
|
56 |
A workaround is to also use C<-override-redirect>. |
57 |
|
58 |
In addition, input shapes don't seem to be well supported in Xorg, |
59 |
which sometimes doe snot egenerate the necessary events for window |
60 |
managers. This is currenty being worked around in this extension by |
61 |
re-setting the input shape after every map event. |
62 |
|
63 |
=cut |
64 |
|
65 |
sub on_start { |
66 |
my ($self) = @_; |
67 |
|
68 |
my $mode = $self->x_resource ("clickthrough"); |
69 |
|
70 |
if ($mode eq "on" or $mode eq "off") { |
71 |
my ($major, $minor) = $self->XShapeQueryVersion; |
72 |
|
73 |
if ($major < 1 or ($major == 1 && $minor < 1)) { |
74 |
warn "clickthrough cannot be enabled since the shape extension is missing or too old\n"; |
75 |
return; |
76 |
} |
77 |
|
78 |
my $set_mode = sub { |
79 |
if ($mode eq "on") { |
80 |
my $reg = urxvt::XCreateRegion; |
81 |
$self->XShapeCombineRegion ($self->parent, urxvt::ShapeInput, 0, 0, $reg, urxvt::ShapeSet); |
82 |
urxvt::XDestroyRegion ($reg); |
83 |
} elsif ($mode eq "off") { |
84 |
$self->XShapeCombineMask ($self->parent, urxvt::ShapeInput, 0, 0, urxvt::None, urxvt::ShapeSet); |
85 |
} |
86 |
}; |
87 |
|
88 |
$set_mode->(); |
89 |
|
90 |
$self->{on_osc_seq_perl} = $self->on (osc_seq_perl => sub { |
91 |
my ($self, $osc, $resp) = @_; |
92 |
|
93 |
if ($osc =~ /^clickthrough:(on|off)\z/) { |
94 |
$mode = $1; |
95 |
$set_mode->(); |
96 |
} |
97 |
}); |
98 |
|
99 |
# at least my x-server does not send a ShapeNotify event to the window manager |
100 |
# for input shapes unless the window is mapped. Works for bounding shapes, so |
101 |
# this is likely an X bug, which we work maround by setting the mask on every map |
102 |
#$self->{on_map_notify} = $self->on (map_notify => $set_mode); |
103 |
} |
104 |
|
105 |
() |
106 |
} |
107 |
|