fvwm-convert-2.6: Note FvwmTheme conversion likely incomplete.
[fvwm.git] / tests / perl / module-gtkwinlist
blob46d96b58ca49c6564778c296ca3d4f5714dc3139
1 #!/usr/bin/perl -w
3 use 5.003;
4 use strict;
6 use lib `fvwm-perllib dir`;
7 use FVWM::Module::Gtk;
8 init Gtk;
10 my $module = new FVWM::Module::Gtk(
11 Name => "FvwmPerlGtkWinList",
12 Mask => M_WINDOW_NAME | M_END_WINDOWLIST | M_STRING | M_ERROR,
15 my $dialog = new Gtk::Dialog;
16 $dialog->set_title("Window List");
17 $dialog->set_border_width(4);
19 my $smode = 'single'; # initial selection mode, may be changed by user
20 my $clist = new_with_titles Gtk::CList(" Id" . " " x 13, " Name" . " " x 20);
21 $clist->set_selection_mode($smode);
22 $clist->signal_connect("click_column", \&sort_list_by_column);
23 $dialog->vbox->add($clist);
25 my $creating_window_list = 0;
26 sub request_window_list () {
27 $creating_window_list = 1;
28 $clist->freeze;
29 $clist->clear;
30 $module->send("Send_WindowList");
33 sub do_command ($) {
34 my $command = shift;
35 foreach ($clist->selection) {
36 $module->send($command, hex($clist->get_text($_, 0)));
40 sub sort_list_by_column ($$) {
41 my $clist = shift;
42 my $column = shift;
44 if ($column == $clist->sort_column()) {
45 if ($clist->sort_type() eq 'ascending') {
46 $clist->set_sort_type('descending');
47 } else {
48 $clist->set_sort_type('ascending');
50 } else {
51 $clist->set_sort_column($column);
53 $clist->sort;
56 my $button = new Gtk::CheckButton "Enable multiple selection";
57 $dialog->vbox->add($button);
58 $button->signal_connect("clicked", sub { $clist->set_selection_mode(
59 $smode = $smode eq 'multiple'? 'single': 'multiple'); });
61 my $hbox = new Gtk::HBox(1, 0);
62 $dialog->vbox->pack_end($hbox, 1, 1, 8);
64 $button = new Gtk::Button "Iconify";
65 $hbox->pack_start($button, 1, 1, 4);
66 $button->signal_connect("clicked", sub { do_command("Iconify"); });
68 $button = new Gtk::Button "WindowShade";
69 $hbox->pack_start($button, 1, 1, 4);
70 $button->signal_connect("clicked", sub { do_command("WindowShade"); });
72 $button = new Gtk::Button "Refresh";
73 $dialog->action_area->pack_start($button, 1, 1, 0);
74 $button->signal_connect("clicked", sub { request_window_list(); });
76 $button = new Gtk::Button "Quit";
77 $dialog->action_area->pack_start($button, 1, 1, 0);
78 $button->signal_connect("clicked", sub { Gtk->main_quit; });
80 $dialog->show_all;
82 $module->add_handler(M_WINDOW_NAME, sub {
83 my ($self, $event) = @_;
84 return unless $creating_window_list;
85 $clist->append(sprintf("0x%07lx", $event->_win_id), $event->_name);
86 });
88 $module->add_handler(M_END_WINDOWLIST, sub {
89 $creating_window_list = 0;
90 $clist->thaw;
91 });
93 $module->add_handler(M_STRING, sub {
94 my $string = $_[1]->_text;
95 my $winid = $dialog->window->XWINDOW();
96 if ($string =~ /^close|stop|quit|exit/i) {
97 Gtk->exit(0);
98 } elsif ($string =~ /^iconify|maximize|windowshade/i) {
99 $module->send($string, $winid)
100 } else {
101 $module->open_error_dialog("Unsupported message: $string");
105 $module->add_default_error_handler;
107 request_window_list();
108 $module->event_loop;