Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env perl
- use X11::Protocol;
- my $ewmh_NET_WM_STATE_REMOVE = 0; # remove/unset property
- my $ewmh_NET_WM_STATE_ADD = 1; # add/set property
- my $ewmh_NET_WM_STATE_TOGGLE = 2; # toggle property
- sub send_client_message {
- my ($x, $win, $msg, $data) = @_;
- my %event = (
- 'name' => 'ClientMessage',
- 'format' => 32,
- 'window' => $win,
- 'type' => $msg,
- 'data' => $data);
- $x->SendEvent($x->root, 0,
- $x->pack_event_mask('SubstructureRedirect', 'SubstructureNotifyMask'),
- $x->pack_event(%event));
- }
- sub set_sticky {
- my ($self, $bool) = @_;
- my $x = $self->{x};
- my $act = $ewmh_NET_WM_STATE_REMOVE;
- $act = $ewmh_NET_WM_STATE_ADD if $bool;
- # $self->exec_async ("wmctrl", "-i", "-r", $self->parent, "-b", "add,sticky");
- send_client_message($x, $self->parent, $x->atom("_NET_WM_STATE"),
- pack("LLLLL", $act,
- $x->atom('_NET_WM_STATE_STICKY'), 0, 0, 0));
- $x->ChangeProperty($self->parent,
- $x->atom("DESKTOP_TERMINAL"), $x->atom("STRING"),
- 8, "Replace", "true");
- # If this call isn't present, it may not work
- }
- sub set_desktop_mode {
- my ($self, $bool) = @_;
- my $x = $self->{x};
- my $act;
- my $window_type;
- if ($bool) {
- $act = $ewmh_NET_WM_STATE_ADD;
- $window_type = "_NET_WM_WINDOW_TYPE_DESKTOP";
- } else {
- $act = $ewmh_NET_WM_STATE_REMOVE;
- $window_type = "_NET_WM_WINDOW_TYPE_NORMAL";
- }
- # $self->exec_async ("wmctrl", "-i", "-r", $self->parent,
- # "-b", "add,skip_pager,skip_taskbar");
- # $self->exec_async ("wmctrl", "-i", "-r", $self->parent,
- # "-b", "add,maximized_horz,maximized_vert");
- # if($bool){
- # my %geom = $x->GetGeometry($x->root);
- # $x->MoveWindow($self->parent, 0, 0);
- # $x->ResizeWindow($self->parent, $geom{width}, $geom{height});
- # }
- send_client_message($x, $self->parent, $x->atom("_NET_WM_STATE"),
- pack("LLLLL", $act,
- $x->atom('_NET_WM_STATE_MAXIMIZED_HORZ'),
- $x->atom('_NET_WM_STATE_MAXIMIZED_VERT'), 0, 0));
- $x->ChangeProperty($self->parent,
- $x->atom("_NET_WM_WINDOW_TYPE"), $x->atom("ATOM"),
- 32, "Replace", pack("L", $x->atom($window_type)));
- send_client_message($x, $self->parent, $x->atom("_NET_WM_STATE"),
- pack("LLLLL", $act,
- $x->atom('_NET_WM_STATE_BELOW'), 0, 0, 0));
- send_client_message($x, $self->parent, $x->atom("_NET_WM_STATE"),
- pack("LLLLL", $act,
- $x->atom('_NET_WM_STATE_SKIP_PAGER'),
- $x->atom('_NET_WM_STATE_SKIP_TASKBAR'), 0, 0));
- $x->ChangeProperty($self->parent,
- $x->atom("DESKTOP_TERMINAL"), $x->atom("STRING"),
- 8, "Replace", "true");
- # If this call isn't present, it may not work
- }
- sub on_init {
- my ($self) = @_;
- print "initialize desktop plugin\n";
- $self->{x} = X11::Protocol->new($self->display_id);
- $self->{desktopmode} = 1;
- $self->{sticky} = 1;
- $self->resource (perl_ext_2 => $self->resource ("perl_ext_2") . ",-desktop");
- ()
- }
- sub on_start {
- my ($self) = @_;
- my $x = $self->{x};
- push @{ $self->{term}{option_popup_hook} }, sub {
- ("desktop mode" => $self->{desktopmode}, sub {
- $self->{desktopmode} = $_[0];
- $self->set_desktop_mode($self->{desktopmode});
- $self->{desktopmode}
- })
- };
- push @{ $self->{term}{option_popup_hook} }, sub {
- ("sticky" => $self->{sticky}, sub {
- $self->{sticky} = $_[0];
- $self->set_sticky($self->{sticky});
- $self->{sticky}
- })
- };
- # my %geom = $x->GetGeometry($x->root);
- # $x->MoveWindow($self->parent, 0, 0);
- # $x->ResizeWindow($self->parent, $geom{width}, $geom{height});
- # $self->XMoveResizeWindow($self->parent, 0, 24, $geom{width}, $geom{height}-48);
- ()
- }
- sub on_map_notify {
- my ($self) = @_;
- my $x = $self->{x};
- $self->set_desktop_mode($self->{desktopmode});
- $self->set_sticky($self->{sticky});
- ()
- }
- sub on_configure_notify {
- my ($self, $event) = @_;
- #$self->set_desktop_mode($self->{desktopmode});
- #$self->set_sticky($self->{sticky});
- ()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement