| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
# A nice interface to "xset" to change X server settings |
| 4 |
# |
| 5 |
# History : |
| 6 |
# 91/11/23 : [email protected], [email protected] : design |
| 7 |
# 92/08/01 : [email protected] : cleaning |
| 8 |
# |
| 9 |
# Tcl/Tk -> Perl translation by Stephen O. Lidie. [email protected] 96/01/24 |
| 10 |
|
| 11 |
require 5.002; |
| 12 |
use English; |
| 13 |
use Tk; |
| 14 |
|
| 15 |
use subs qw(cancel dispsettings labelentry quit readsettings writesettings); |
| 16 |
|
| 17 |
sub labelentry { |
| 18 |
|
| 19 |
# Create all windows, and pack them. |
| 20 |
|
| 21 |
my ($parent, $path, $text, $length) = @_; |
| 22 |
|
| 23 |
${$path} = $parent->Frame(); |
| 24 |
$w = "${path}_label"; |
| 25 |
${$w} = ${$path}->Label(-text => $text); |
| 26 |
${$w}->pack(-side => 'left', -expand => 'y'); |
| 27 |
$w = "${path}_entry"; |
| 28 |
${$w} = ${$path}->Entry(-width => $length, -relief => 'sunken'); |
| 29 |
${$w}->pack(-side => 'right', -expand => 'y'); |
| 30 |
|
| 31 |
} # end labelentry |
| 32 |
|
| 33 |
sub createwindows { |
| 34 |
|
| 35 |
# Buttons |
| 36 |
|
| 37 |
$buttons = $MW->Frame(); |
| 38 |
$buttons_ok = $buttons->Button(-command => \&ok, -text => 'Ok'); |
| 39 |
$buttons_apply = $buttons->Button( |
| 40 |
-command => \&writesettings, |
| 41 |
-text => 'Apply', |
| 42 |
); |
| 43 |
$buttons_cancel = $buttons->Button( |
| 44 |
-command => \&cancel, |
| 45 |
-text => 'Cancel', |
| 46 |
); |
| 47 |
$buttons_quit = $buttons->Button(-command => \&quit, -text => 'Quit'); |
| 48 |
$buttons_ok->pack(-side => 'left', -expand => 'yes', -pady => '5'); |
| 49 |
$buttons_apply->pack(-side => 'left', -expand => 'yes', -pady => '5'); |
| 50 |
$buttons_cancel->pack(-side => 'left', -expand => 'yes', -pady => '5'); |
| 51 |
$buttons_quit->pack(-side => 'left', -expand => 'yes', -pady => '5'); |
| 52 |
|
| 53 |
# Bell settings |
| 54 |
|
| 55 |
$bell = $MW->Frame(-relief => 'raised', -borderwidth => '2'); |
| 56 |
$bell_label = $bell->Label(-text => 'Bell Settings'); |
| 57 |
$bell_vol = $bell->Scale( |
| 58 |
-from => '0', |
| 59 |
-to => '100', |
| 60 |
-length => '200', |
| 61 |
-tickinterval => '20', |
| 62 |
-label => 'Volume (%)', |
| 63 |
-orient => 'horizontal', |
| 64 |
); |
| 65 |
$bell_val = $bell->Frame(); |
| 66 |
labelentry $bell_val, 'bell_val_pit', 'Pitch (Hz)', 6; |
| 67 |
labelentry $bell_val, 'bell_val_dur', 'Duration (ms)', 6; |
| 68 |
$bell_val_pit->pack(-side => 'left', -padx => '5'); |
| 69 |
$bell_val_dur->pack(-side => 'right', -padx => '5'); |
| 70 |
$bell_label->pack(-side => 'top', -expand => 'yes'); |
| 71 |
$bell_vol->pack(-side => 'top', -expand => 'yes'); |
| 72 |
$bell_val->pack(-side => 'top', -expand => 'yes'); |
| 73 |
|
| 74 |
# Keyboard settings |
| 75 |
|
| 76 |
$kbd = $MW->Frame(-relief => 'raised', -borderwidth => '2'); |
| 77 |
$kbd_label = $kbd->Label(-text => 'Keyboard Repeat Settings'); |
| 78 |
$kbd_val = $kbd->Frame(); |
| 79 |
$kbd_val_onoff = $kbd_val->Checkbutton( |
| 80 |
-text => 'On', |
| 81 |
-onvalue => 'on', |
| 82 |
-offvalue => 'off', |
| 83 |
-variable => \$kbdrpt, |
| 84 |
-relief => 'flat', |
| 85 |
); |
| 86 |
$kbd_val_cli = $kbd_val->Scale( |
| 87 |
-from => '0', |
| 88 |
-to => '100', |
| 89 |
-length => '200', |
| 90 |
-tickinterval => '20', |
| 91 |
-label => 'Click Volume (%)', |
| 92 |
-orient => 'horizontal', |
| 93 |
); |
| 94 |
$kbd_val_onoff->pack(-side => 'left', -expand => 'yes', -fill => 'both'); |
| 95 |
$kbd_val_cli->pack(-side => 'left', -expand => 'yes'); |
| 96 |
$kbd_label->pack(-side => 'top', -expand => 'yes'); |
| 97 |
$kbd_val->pack(-side => 'top', -expand => 1, -pady => '2', -fill => 'x'); |
| 98 |
|
| 99 |
# Mouse settings |
| 100 |
|
| 101 |
$mouse = $MW->Frame(-relief => 'raised', -borderwidth => '2'); |
| 102 |
$mouse_label = $mouse->Label(-text => 'Mouse Settings'); |
| 103 |
$mouse_hor = $mouse->Frame(); |
| 104 |
labelentry $mouse_hor, 'mouse_hor_acc', 'Acceleration', 3; |
| 105 |
labelentry $mouse_hor, 'mouse_hor_thr', 'Threshold (pixels)', 3; |
| 106 |
$mouse_hor_acc->pack(-side => 'left'); |
| 107 |
$mouse_hor_thr->pack(-side => 'right'); |
| 108 |
$mouse_label->pack(-side => 'top'); |
| 109 |
$mouse_hor->pack(-side => 'top', -expand => 'yes'); |
| 110 |
|
| 111 |
# Screen Saver settings |
| 112 |
|
| 113 |
$screen = $MW->Frame(-relief => 'raised', -borderwidth => '2'); |
| 114 |
$screen_label = $screen->Label(-text => 'Screen-saver Settings'); |
| 115 |
$screen_val = $screen->Frame(); |
| 116 |
$screen_val_rb = $screen_val->Frame(); |
| 117 |
$screen_val_rb_blank = $screen_val_rb->Radiobutton( |
| 118 |
-text => 'Blank', |
| 119 |
-relief => 'flat', |
| 120 |
-value => 'blank', |
| 121 |
-variable => \$screenbla, |
| 122 |
); |
| 123 |
$screen_val_rb_pat = $screen_val_rb->Radiobutton( |
| 124 |
-text => 'Pattern', |
| 125 |
-relief => 'flat', |
| 126 |
-value => 'noblank', |
| 127 |
-variable => \$screenbla, |
| 128 |
); |
| 129 |
$screen_val_rb_blank->pack(-side => 'top', -pady => '2', -anchor => 'w'); |
| 130 |
$screen_val_rb_pat->pack(-side => 'top', -pady => '2', -anchor => 'w'); |
| 131 |
$screen_val_le = $screen_val->Frame(); |
| 132 |
labelentry $screen_val_le, 'screen_val_le_tim', 'Timeout (s)', 5; |
| 133 |
labelentry $screen_val_le, 'screen_val_le_cyc', 'Cycle (s)', 5; |
| 134 |
$screen_val_le_tim->pack(-side => 'top', -pady => '2', -anchor => 'e'); |
| 135 |
$screen_val_le_cyc->pack(-side => 'top', -pady => '2', -anchor => 'e'); |
| 136 |
$screen_val_rb->pack(-side => 'left'); |
| 137 |
$screen_val_le->pack(-side => 'left'); |
| 138 |
|
| 139 |
$screen_label->pack(-side => 'top'); |
| 140 |
$screen_val->pack(-side => 'top', -expand => 'y'); |
| 141 |
|
| 142 |
# Main window |
| 143 |
|
| 144 |
$buttons->pack(-side => 'top', -fill => 'both'); |
| 145 |
my(@pl)= (-side => 'top', -fill => 'both', -ipady => '5', -expand =>1); |
| 146 |
$bell->pack(@pl); |
| 147 |
$kbd->pack(@pl); |
| 148 |
$mouse->pack(@pl); |
| 149 |
$screen->pack(@pl); |
| 150 |
|
| 151 |
# Let the user resize our window |
| 152 |
|
| 153 |
$MW->minsize(10, 10); |
| 154 |
|
| 155 |
} # end createwindows |
| 156 |
|
| 157 |
|
| 158 |
# Main program |
| 159 |
|
| 160 |
$MW = MainWindow->new; |
| 161 |
|
| 162 |
readsettings; |
| 163 |
createwindows; |
| 164 |
dispsettings; |
| 165 |
|
| 166 |
MainLoop; |
| 167 |
|
| 168 |
# Define button actions. |
| 169 |
|
| 170 |
sub quit { |
| 171 |
exit; |
| 172 |
} |
| 173 |
|
| 174 |
sub ok { |
| 175 |
writesettings; |
| 176 |
quit; |
| 177 |
} |
| 178 |
|
| 179 |
sub cancel { |
| 180 |
readsettings; |
| 181 |
dispsettings; |
| 182 |
} |
| 183 |
|
| 184 |
# `apply' is just "writesettings". |
| 185 |
|
| 186 |
sub readsettings { |
| 187 |
|
| 188 |
# Read the `xset' output to get current setting. |
| 189 |
|
| 190 |
$kbdrpt = "on"; |
| 191 |
$kbdcli = 0; |
| 192 |
$bellvol = 100; |
| 193 |
$bellpit = 440; |
| 194 |
$belldur = 100; |
| 195 |
$mouseacc = "3/1"; |
| 196 |
$mousethr = 4; |
| 197 |
$screenbla = "blank"; |
| 198 |
$screentim = 600; |
| 199 |
$screencyc = 600; |
| 200 |
|
| 201 |
open XFD, "xset q |"; |
| 202 |
while (<XFD>) { |
| 203 |
@line = split ' '; |
| 204 |
my $kw = $line[0]; |
| 205 |
|
| 206 |
if ($kw eq 'auto') { |
| 207 |
my $rpt = $line[1]; |
| 208 |
if ($rpt eq 'repeat:') { |
| 209 |
$kbdrpt = $line[2]; |
| 210 |
$kbdcli = $line[6]; |
| 211 |
} |
| 212 |
} elsif ($kw eq 'bell') { |
| 213 |
$bellvol = $line[2]; |
| 214 |
$bellpit = $line[5]; |
| 215 |
$belldur = $line[8]; |
| 216 |
} elsif ($kw eq 'acceleration:') { |
| 217 |
$mouseacc = $line[1]; |
| 218 |
$mousethr = $line[3]; |
| 219 |
} elsif ($kw eq 'prefer') { |
| 220 |
my $bla = $line[2]; |
| 221 |
$screenbla = ($bla eq 'yes' ? 'blank' : 'noblank'); |
| 222 |
} elsif ($kw eq 'timeout:') { |
| 223 |
$screentim = $line[1]; |
| 224 |
$screencyc = $line[3]; |
| 225 |
} |
| 226 |
} # whilend |
| 227 |
close XFD; |
| 228 |
|
| 229 |
} # end readsettings |
| 230 |
|
| 231 |
sub writesettings { |
| 232 |
|
| 233 |
# execute an `xset' command to propagate current values. |
| 234 |
|
| 235 |
$bellvol = $bell_vol->get; |
| 236 |
$bellpit = $bell_val_pit_entry->get; |
| 237 |
$belldur = $bell_val_dur_entry->get; |
| 238 |
|
| 239 |
if ($kbdrpt eq 'on') { |
| 240 |
$kbdcli = $kbd_val_cli->get; |
| 241 |
} else { |
| 242 |
$kbdcli = 'off'; |
| 243 |
} |
| 244 |
|
| 245 |
$mouseacc = $mouse_hor_acc_entry->get; |
| 246 |
$mousethr = $mouse_hor_thr_entry->get; |
| 247 |
|
| 248 |
$screentim = $screen_val_le_tim_entry->get; |
| 249 |
$screencyc = $screen_val_le_cyc_entry->get; |
| 250 |
|
| 251 |
system "xset b $bellvol $bellpit $belldur c $kbdcli r $kbdrpt m $mouseacc $mousethr s $screentim $screencyc s $screenbla"; |
| 252 |
|
| 253 |
} # end writesettings |
| 254 |
|
| 255 |
sub dispsettings { |
| 256 |
|
| 257 |
# Update `xset' values in all widgets. |
| 258 |
|
| 259 |
$bell_vol->set($bellvol); |
| 260 |
$bell_val_pit_entry->delete('0', 'end'); |
| 261 |
$bell_val_pit_entry->insert('0', $bellpit); |
| 262 |
$bell_val_dur_entry->delete('0', 'end'); |
| 263 |
$bell_val_dur_entry->insert('0', $belldur); |
| 264 |
|
| 265 |
if ($kbdrpt eq 'on') { |
| 266 |
$kbd_val_onoff->select; |
| 267 |
} else { |
| 268 |
$kbd_val_onoff->deselect; |
| 269 |
} |
| 270 |
$kbd_val_cli->set($kbdcli); |
| 271 |
|
| 272 |
$mouse_hor_acc_entry->delete('0', 'end'); |
| 273 |
$mouse_hor_acc_entry->insert('0', $mouseacc); |
| 274 |
$mouse_hor_thr_entry->delete('0', 'end'); |
| 275 |
$mouse_hor_thr_entry->insert('0', $mousethr); |
| 276 |
|
| 277 |
if ($screenbla eq 'blank') { |
| 278 |
$screen_val_rb_blank->select; |
| 279 |
$screen_val_rb_pat->select; |
| 280 |
} else { |
| 281 |
$screen_val_rb_blank->deselect; |
| 282 |
$screen_val_rb_pat->deselect; |
| 283 |
} |
| 284 |
$screen_val_le_tim_entry->delete('0', 'end'); |
| 285 |
$screen_val_le_tim_entry->insert('0', $screentim); |
| 286 |
$screen_val_le_cyc_entry->delete('0', 'end'); |
| 287 |
$screen_val_le_cyc_entry->insert('0', $screencyc); |
| 288 |
|
| 289 |
} # end dispsettings |