2006-03-02 Serge Koksharov <gentoosiast dog yandex dot ru>
[fvwm.git] / tests / perl / module-gtkwinlist
blobf5806b4a15e476c69ac34ccd0cc9e851b4a9a165
1 #!/usr/bin/perl -w
3 use 5.003;
4 use strict;
5 use Gtk;
6 init Gtk;
8 use lib `fvwm-perllib dir`;
9 use FVWM::Module::Gtk;
11 my $module = new FVWM::Module::Gtk(
12 Name => "FvwmPerlGtkWinList",
13 Mask => M_WINDOW_NAME | M_END_WINDOWLIST | M_STRING | M_ERROR,
16 my $dialog = new Gtk::Dialog;
17 $dialog->set_title("Window List");
18 $dialog->set_border_width(4);
20 my $smode = 'single'; # initial selection mode, may be changed by user
21 my $clist = new_with_titles Gtk::CList(" Id" . " " x 13, " Name" . " " x 20);
22 $clist->set_selection_mode($smode);
23 $clist->signal_connect("click_column", \&sortListByColumn);
24 $dialog->vbox->add($clist);
26 my $creatingWindowList = 0;
27 sub requestWindowList () {
28 $creatingWindowList = 1;
29 $clist->freeze;
30 $clist->clear;
31 $module->send("Send_WindowList");
34 sub doCommand ($) {
35 my $command = shift;
36 foreach ($clist->selection) {
37 $module->send($command, hex($clist->get_text($_, 0)));
41 sub sortListByColumn ($$) {
42 my $clist = shift;
43 my $column = shift;
45 if ($column == $clist->sort_column()) {
46 if ($clist->sort_type() eq 'ascending') {
47 $clist->set_sort_type('descending');
48 } else {
49 $clist->set_sort_type('ascending');
51 } else {
52 $clist->set_sort_column($column);
54 $clist->sort;
57 my $button = new Gtk::CheckButton "Enable multiple selection";
58 $dialog->vbox->add($button);
59 $button->signal_connect("clicked", sub { $clist->set_selection_mode(
60 $smode = $smode eq 'multiple'? 'single': 'multiple'); });
62 my $hbox = new Gtk::HBox(1, 0);
63 $dialog->vbox->pack_end($hbox, 1, 1, 8);
65 $button = new Gtk::Button "Iconify";
66 $hbox->pack_start($button, 1, 1, 4);
67 $button->signal_connect("clicked", sub { doCommand("Iconify"); });
69 $button = new Gtk::Button "WindowShade";
70 $hbox->pack_start($button, 1, 1, 4);
71 $button->signal_connect("clicked", sub { doCommand("WindowShade"); });
73 $button = new Gtk::Button "Refresh";
74 $dialog->action_area->pack_start($button, 1, 1, 0);
75 $button->signal_connect("clicked", sub { requestWindowList(); });
77 $button = new Gtk::Button "Quit";
78 $dialog->action_area->pack_start($button, 1, 1, 0);
79 $button->signal_connect("clicked", sub { Gtk->main_quit; });
81 $dialog->show_all;
83 $module->addHandler(M_WINDOW_NAME, sub {
84 my ($self, $event) = @_;
85 return unless $creatingWindowList;
86 $clist->append(sprintf("0x%07lx", $event->_win_id), $event->_name);
87 });
89 $module->addHandler(M_END_WINDOWLIST, sub {
90 $creatingWindowList = 0;
91 $clist->thaw;
92 });
94 $module->addHandler(M_STRING, sub {
95 my $string = $_[1]->_text;
96 my $winid = $dialog->window->XWINDOW();
97 if ($string =~ /^close|stop|quit|exit/i) {
98 Gtk->exit(0);
99 } elsif ($string =~ /^iconify|maximize|windowshade/i) {
100 $module->send($string, $winid)
101 } else {
102 $module->openErrorDialog("Unsupported message: $string");
106 $module->addDefaultErrorHandler;
108 requestWindowList();
109 $module->eventLoop;