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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
#!/usr/bin/env perl
# A nice interface to "xset" to change X server settings
#
# History :
# 91/11/23 : pda@masi.ibp.fr, jt@ratp.fr : design
# 92/08/01 : pda@masi.ibp.fr : cleaning
#
# Tcl/Tk -> Perl translation by Stephen O. Lidie. lusol@Lehigh.EDU 96/01/24
require 5.002;
use English;
use Tk;
use subs qw(cancel dispsettings labelentry quit readsettings writesettings);
sub labelentry {
# Create all windows, and pack them.
my ($parent, $path, $text, $length) = @_;
${$path} = $parent->Frame();
$w = "${path}_label";
${$w} = ${$path}->Label(-text => $text);
${$w}->pack(-side => 'left', -expand => 'y');
$w = "${path}_entry";
${$w} = ${$path}->Entry(-width => $length, -relief => 'sunken');
${$w}->pack(-side => 'right', -expand => 'y');
} # end labelentry
sub createwindows {
# Buttons
$buttons = $MW->Frame();
$buttons_ok = $buttons->Button(-command => \&ok, -text => 'Ok');
$buttons_apply = $buttons->Button(
-command => \&writesettings,
-text => 'Apply',
);
$buttons_cancel = $buttons->Button(
-command => \&cancel,
-text => 'Cancel',
);
$buttons_quit = $buttons->Button(-command => \&quit, -text => 'Quit');
$buttons_ok->pack(-side => 'left', -expand => 'yes', -pady => '5');
$buttons_apply->pack(-side => 'left', -expand => 'yes', -pady => '5');
$buttons_cancel->pack(-side => 'left', -expand => 'yes', -pady => '5');
$buttons_quit->pack(-side => 'left', -expand => 'yes', -pady => '5');
# Bell settings
$bell = $MW->Frame(-relief => 'raised', -borderwidth => '2');
$bell_label = $bell->Label(-text => 'Bell Settings');
$bell_vol = $bell->Scale(
-from => '0',
-to => '100',
-length => '200',
-tickinterval => '20',
-label => 'Volume (%)',
-orient => 'horizontal',
);
$bell_val = $bell->Frame();
labelentry $bell_val, 'bell_val_pit', 'Pitch (Hz)', 6;
labelentry $bell_val, 'bell_val_dur', 'Duration (ms)', 6;
$bell_val_pit->pack(-side => 'left', -padx => '5');
$bell_val_dur->pack(-side => 'right', -padx => '5');
$bell_label->pack(-side => 'top', -expand => 'yes');
$bell_vol->pack(-side => 'top', -expand => 'yes');
$bell_val->pack(-side => 'top', -expand => 'yes');
# Keyboard settings
$kbd = $MW->Frame(-relief => 'raised', -borderwidth => '2');
$kbd_label = $kbd->Label(-text => 'Keyboard Repeat Settings');
$kbd_val = $kbd->Frame();
$kbd_val_onoff = $kbd_val->Checkbutton(
-text => 'On',
-onvalue => 'on',
-offvalue => 'off',
-variable => \$kbdrpt,
-relief => 'flat',
);
$kbd_val_cli = $kbd_val->Scale(
-from => '0',
-to => '100',
-length => '200',
-tickinterval => '20',
-label => 'Click Volume (%)',
-orient => 'horizontal',
);
$kbd_val_onoff->pack(-side => 'left', -expand => 'yes', -fill => 'both');
$kbd_val_cli->pack(-side => 'left', -expand => 'yes');
$kbd_label->pack(-side => 'top', -expand => 'yes');
$kbd_val->pack(-side => 'top', -expand => 1, -pady => '2', -fill => 'x');
# Mouse settings
$mouse = $MW->Frame(-relief => 'raised', -borderwidth => '2');
$mouse_label = $mouse->Label(-text => 'Mouse Settings');
$mouse_hor = $mouse->Frame();
labelentry $mouse_hor, 'mouse_hor_acc', 'Acceleration', 3;
labelentry $mouse_hor, 'mouse_hor_thr', 'Threshold (pixels)', 3;
$mouse_hor_acc->pack(-side => 'left');
$mouse_hor_thr->pack(-side => 'right');
$mouse_label->pack(-side => 'top');
$mouse_hor->pack(-side => 'top', -expand => 'yes');
# Screen Saver settings
$screen = $MW->Frame(-relief => 'raised', -borderwidth => '2');
$screen_label = $screen->Label(-text => 'Screen-saver Settings');
$screen_val = $screen->Frame();
$screen_val_rb = $screen_val->Frame();
$screen_val_rb_blank = $screen_val_rb->Radiobutton(
-text => 'Blank',
-relief => 'flat',
-value => 'blank',
-variable => \$screenbla,
);
$screen_val_rb_pat = $screen_val_rb->Radiobutton(
-text => 'Pattern',
-relief => 'flat',
-value => 'noblank',
-variable => \$screenbla,
);
$screen_val_rb_blank->pack(-side => 'top', -pady => '2', -anchor => 'w');
$screen_val_rb_pat->pack(-side => 'top', -pady => '2', -anchor => 'w');
$screen_val_le = $screen_val->Frame();
labelentry $screen_val_le, 'screen_val_le_tim', 'Timeout (s)', 5;
labelentry $screen_val_le, 'screen_val_le_cyc', 'Cycle (s)', 5;
$screen_val_le_tim->pack(-side => 'top', -pady => '2', -anchor => 'e');
$screen_val_le_cyc->pack(-side => 'top', -pady => '2', -anchor => 'e');
$screen_val_rb->pack(-side => 'left');
$screen_val_le->pack(-side => 'left');
$screen_label->pack(-side => 'top');
$screen_val->pack(-side => 'top', -expand => 'y');
# Main window
$buttons->pack(-side => 'top', -fill => 'both');
my(@pl)= (-side => 'top', -fill => 'both', -ipady => '5', -expand =>1);
$bell->pack(@pl);
$kbd->pack(@pl);
$mouse->pack(@pl);
$screen->pack(@pl);
# Let the user resize our window
$MW->minsize(10, 10);
} # end createwindows
# Main program
$MW = MainWindow->new;
readsettings;
createwindows;
dispsettings;
MainLoop;
# Define button actions.
sub quit {
exit;
}
sub ok {
writesettings;
quit;
}
sub cancel {
readsettings;
dispsettings;
}
# `apply' is just "writesettings".
sub readsettings {
# Read the `xset' output to get current setting.
$kbdrpt = "on";
$kbdcli = 0;
$bellvol = 100;
$bellpit = 440;
$belldur = 100;
$mouseacc = "3/1";
$mousethr = 4;
$screenbla = "blank";
$screentim = 600;
$screencyc = 600;
open XFD, "xset q |";
while (<XFD>) {
@line = split ' ';
my $kw = $line[0];
if ($kw eq 'auto') {
my $rpt = $line[1];
if ($rpt eq 'repeat:') {
$kbdrpt = $line[2];
$kbdcli = $line[6];
}
} elsif ($kw eq 'bell') {
$bellvol = $line[2];
$bellpit = $line[5];
$belldur = $line[8];
} elsif ($kw eq 'acceleration:') {
$mouseacc = $line[1];
$mousethr = $line[3];
} elsif ($kw eq 'prefer') {
my $bla = $line[2];
$screenbla = ($bla eq 'yes' ? 'blank' : 'noblank');
} elsif ($kw eq 'timeout:') {
$screentim = $line[1];
$screencyc = $line[3];
}
} # whilend
close XFD;
} # end readsettings
sub writesettings {
# execute an `xset' command to propagate current values.
$bellvol = $bell_vol->get;
$bellpit = $bell_val_pit_entry->get;
$belldur = $bell_val_dur_entry->get;
if ($kbdrpt eq 'on') {
$kbdcli = $kbd_val_cli->get;
} else {
$kbdcli = 'off';
}
$mouseacc = $mouse_hor_acc_entry->get;
$mousethr = $mouse_hor_thr_entry->get;
$screentim = $screen_val_le_tim_entry->get;
$screencyc = $screen_val_le_cyc_entry->get;
system "xset b $bellvol $bellpit $belldur c $kbdcli r $kbdrpt m $mouseacc $mousethr s $screentim $screencyc s $screenbla";
} # end writesettings
sub dispsettings {
# Update `xset' values in all widgets.
$bell_vol->set($bellvol);
$bell_val_pit_entry->delete('0', 'end');
$bell_val_pit_entry->insert('0', $bellpit);
$bell_val_dur_entry->delete('0', 'end');
$bell_val_dur_entry->insert('0', $belldur);
if ($kbdrpt eq 'on') {
$kbd_val_onoff->select;
} else {
$kbd_val_onoff->deselect;
}
$kbd_val_cli->set($kbdcli);
$mouse_hor_acc_entry->delete('0', 'end');
$mouse_hor_acc_entry->insert('0', $mouseacc);
$mouse_hor_thr_entry->delete('0', 'end');
$mouse_hor_thr_entry->insert('0', $mousethr);
if ($screenbla eq 'blank') {
$screen_val_rb_blank->select;
$screen_val_rb_pat->select;
} else {
$screen_val_rb_blank->deselect;
$screen_val_rb_pat->deselect;
}
$screen_val_le_tim_entry->delete('0', 'end');
$screen_val_le_tim_entry->insert('0', $screentim);
$screen_val_le_cyc_entry->delete('0', 'end');
$screen_val_le_cyc_entry->insert('0', $screencyc);
} # end dispsettings
|