File: view-root.pl

package info (click to toggle)
libx11-protocol-other-perl 29-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,692 kB
  • ctags: 555
  • sloc: perl: 17,174; ansic: 624; sh: 238; lisp: 143; makefile: 40
file content (133 lines) | stat: -rwxr-xr-x 4,063 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/perl -w

# Copyright 2012, 2013 Kevin Ryde

# This file is part of X11-Protocol-Other.
#
# X11-Protocol-Other is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3, or (at your option) any
# later version.
#
# X11-Protocol-Other is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with X11-Protocol-Other.  If not, see <http://www.gnu.org/licenses/>.

use strict;
use FindBin;
use X11::AtomConstants;
use X11::Protocol;
use X11::Protocol::Other;
use X11::Protocol::WM;

# uncomment this to run the ### lines
use Smart::Comments;


my $X = X11::Protocol->new;
my $root = (X11::Protocol::WM::root_to_virtual_root($X,$X->root)
            || $X->root);
my $xrootpmap_id;
{
  my ($value, $type, $format, $bytes_after)
    = $X->GetProperty ($root, $X->atom('_XROOTPMAP_ID'),
                       X11::AtomConstants::PIXMAP(),    # type
                       0,    # offset
                       1,    # length
                       0);   # delete;
  if ($value) {
    $xrootpmap_id = unpack 'L', $value;
  }
}

if ($xrootpmap_id) {
  # by flashing the _XROOTPMAP_ID
  my ($width, $height) = X11::Protocol::Other::window_size ($X, $root);

  my $error;
  local $X->{'error_handler'} = sub {
    my ($X, $data) = @_;
    $error = 1;
  };
  my $window = $X->new_rsrc;
  $X->CreateWindow ($window,
                    $root,            # parent
                    'InputOutput',    # class
                    0,                # depth, from parent
                    'CopyFromParent', # visual
                    0,0,              # x,y
                    $width,$height,
                    0,                # border
                    background_pixmap => $xrootpmap_id,
                    # background_pixel  => 0x00FFFF,
                    override_redirect => 1,
                    # save_under        => 1,
                    # backing_store     => 'Always',
                    # bit_gravity       => 'Static',
                    # event_mask        =>
                    # $X->pack_event_mask('Exposure',
                    #                     'ColormapChange',
                    #                     'VisibilityChange',),
                   );
  $X->QueryPointer($root); # sync
  if ($error) {
    undef $xrootpmap_id;
  } else {
    X11::Protocol::WM::set_wm_name ($X, $window, $FindBin::Script);
    X11::Protocol::WM::set_wm_hints
        ($X, $window, input => 0);
    X11::Protocol::WM::set_net_wm_window_type ($X, $window, 'SPLASH');
    $X->MapWindow ($window);
    $X->ClearArea ($window, 0,0,0,0);
    $X->flush;
    sleep 1;
    exit 0;
  }
}

if (! $xrootpmap_id) {
  # by iconifying everything temporarily

  my ($root, $root_parent, @toplevels) = $X->QueryTree($X->root);

  my ($focus_window, $focus_revert_to) = $X->GetInputFocus;

  my @remap;
  foreach my $frame (@toplevels) {
    my $window = X11::Protocol::WM::frame_window_to_client($X,$frame) || next;

    my ($state, $icon_window) = X11::Protocol::WM::get_wm_state($X,$window);
    if (($state||'') eq 'NormalState') {
      ### WM_NAME: $X->GetProperty($window, $X->atom('WM_NAME'), $X->atom('STRING'), 0, 999, 0)

      X11::Protocol::WM::iconify($X, $window, $root);
      push @remap, $window;
    }

    # my %attr = $X->GetWindowAttributes ($window);
    # if ($attr{'map_state'} eq 'Viewable') {
    #   $X->UnmapWindow ($window);
    #   push @remap, $window;
    # }
  }

  $X->flush;
  $X->QueryPointer($root); # sync
  sleep 5;

  ### @remap
  foreach my $window (@remap) {
    $X->MapWindow ($window);
  }
  $X->flush;
  $X->QueryPointer($root); # sync
  sleep 1;
  $X->SetInputFocus($focus_window, $focus_revert_to, 0);

  $X->QueryPointer($root); # sync
}
exit 0;