Advertisement
Guest User

Mildred

a guest
Aug 26th, 2008
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.03 KB | None | 0 0
  1. #! /usr/bin/env perl
  2.  
  3. use X11::Protocol;
  4.  
  5. my $ewmh_NET_WM_STATE_REMOVE      = 0;    # remove/unset property
  6. my $ewmh_NET_WM_STATE_ADD         = 1;    # add/set property
  7. my $ewmh_NET_WM_STATE_TOGGLE      = 2;    # toggle property
  8.  
  9.  
  10.  
  11. sub send_client_message {
  12.   my ($x, $win, $msg, $data) = @_;
  13.   my %event = (
  14.     'name'      => 'ClientMessage',
  15.     'format'    => 32,
  16.     'window'    => $win,
  17.     'type'      => $msg,
  18.     'data'      => $data);
  19.   $x->SendEvent($x->root, 0,
  20.     $x->pack_event_mask('SubstructureRedirect', 'SubstructureNotifyMask'),
  21.     $x->pack_event(%event));
  22. }
  23.  
  24. sub set_sticky {
  25.   my ($self, $bool) = @_;
  26.   my $x = $self->{x};
  27.  
  28.   my $act = $ewmh_NET_WM_STATE_REMOVE;
  29.   $act = $ewmh_NET_WM_STATE_ADD if $bool;
  30.  
  31. #   $self->exec_async ("wmctrl", "-i", "-r", $self->parent, "-b", "add,sticky");
  32.  
  33.   send_client_message($x, $self->parent, $x->atom("_NET_WM_STATE"),
  34.     pack("LLLLL", $act,
  35.       $x->atom('_NET_WM_STATE_STICKY'), 0, 0, 0));
  36.  
  37.   $x->ChangeProperty($self->parent,
  38.     $x->atom("DESKTOP_TERMINAL"), $x->atom("STRING"),
  39.     8, "Replace", "true");
  40.     # If this call isn't present, it may not work
  41. }
  42.  
  43. sub set_desktop_mode {
  44.   my ($self, $bool) = @_;
  45.   my $x = $self->{x};
  46.  
  47.   my $act;
  48.   my $window_type;
  49.   if ($bool) {
  50.     $act = $ewmh_NET_WM_STATE_ADD;
  51.     $window_type = "_NET_WM_WINDOW_TYPE_DESKTOP";
  52.   } else {
  53.     $act = $ewmh_NET_WM_STATE_REMOVE;
  54.     $window_type = "_NET_WM_WINDOW_TYPE_NORMAL";
  55.   }
  56.  
  57. #   $self->exec_async ("wmctrl", "-i", "-r", $self->parent,
  58. #     "-b", "add,skip_pager,skip_taskbar");
  59. #   $self->exec_async ("wmctrl", "-i", "-r", $self->parent,
  60. #     "-b", "add,maximized_horz,maximized_vert");
  61.  
  62. #   if($bool){
  63. #     my %geom = $x->GetGeometry($x->root);
  64. #     $x->MoveWindow($self->parent, 0, 0);
  65. #     $x->ResizeWindow($self->parent, $geom{width}, $geom{height});
  66. #   }
  67.  
  68.   send_client_message($x, $self->parent, $x->atom("_NET_WM_STATE"),
  69.     pack("LLLLL", $act,
  70.       $x->atom('_NET_WM_STATE_MAXIMIZED_HORZ'),
  71.       $x->atom('_NET_WM_STATE_MAXIMIZED_VERT'), 0, 0));
  72.   $x->ChangeProperty($self->parent,
  73.     $x->atom("_NET_WM_WINDOW_TYPE"), $x->atom("ATOM"),
  74.     32, "Replace", pack("L", $x->atom($window_type)));
  75.   send_client_message($x, $self->parent, $x->atom("_NET_WM_STATE"),
  76.     pack("LLLLL", $act,
  77.       $x->atom('_NET_WM_STATE_BELOW'), 0, 0, 0));
  78.   send_client_message($x, $self->parent, $x->atom("_NET_WM_STATE"),
  79.     pack("LLLLL", $act,
  80.       $x->atom('_NET_WM_STATE_SKIP_PAGER'),
  81.       $x->atom('_NET_WM_STATE_SKIP_TASKBAR'), 0, 0));
  82.  
  83.   $x->ChangeProperty($self->parent,
  84.     $x->atom("DESKTOP_TERMINAL"), $x->atom("STRING"),
  85.     8, "Replace", "true");
  86.     # If this call isn't present, it may not work
  87. }
  88.  
  89.  
  90. sub on_init {
  91.   my ($self) = @_;
  92.   print "initialize desktop plugin\n";
  93.  
  94.   $self->{x} = X11::Protocol->new($self->display_id);
  95.   $self->{desktopmode} = 1;
  96.   $self->{sticky} = 1;
  97.  
  98.   $self->resource (perl_ext_2 => $self->resource ("perl_ext_2") . ",-desktop");
  99.  
  100.   ()
  101. }
  102.  
  103. sub on_start {
  104.   my ($self) = @_;
  105.   my $x = $self->{x};
  106.  
  107.   push @{ $self->{term}{option_popup_hook} }, sub {
  108.     ("desktop mode" => $self->{desktopmode}, sub {
  109.       $self->{desktopmode} = $_[0];
  110.       $self->set_desktop_mode($self->{desktopmode});
  111.       $self->{desktopmode}
  112.     })
  113.   };
  114.   push @{ $self->{term}{option_popup_hook} }, sub {
  115.     ("sticky" => $self->{sticky}, sub {
  116.       $self->{sticky} = $_[0];
  117.       $self->set_sticky($self->{sticky});
  118.       $self->{sticky}
  119.     })
  120.   };
  121.  
  122. #   my %geom = $x->GetGeometry($x->root);
  123. #   $x->MoveWindow($self->parent, 0, 0);
  124. #   $x->ResizeWindow($self->parent, $geom{width}, $geom{height});
  125. #   $self->XMoveResizeWindow($self->parent, 0, 24, $geom{width}, $geom{height}-48);
  126.  
  127.   ()
  128. }
  129.  
  130. sub on_map_notify {
  131.   my ($self) = @_;
  132.   my $x = $self->{x};
  133.  
  134.   $self->set_desktop_mode($self->{desktopmode});
  135.   $self->set_sticky($self->{sticky});
  136.  
  137.   ()
  138. }
  139.  
  140. sub on_configure_notify {
  141.   my ($self, $event) = @_;
  142.  
  143.   #$self->set_desktop_mode($self->{desktopmode});
  144.   #$self->set_sticky($self->{sticky});
  145.  
  146.   ()
  147. }
  148.  
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement