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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# ixset --
# A nice interface to "xset" to change X server settings
#
require 'tk'
class Xsettings
#
# Button actions
#
def quit
@root.destroy
end
def ok
writesettings
quit
end
def cancel
readsettings
dispsettings
@btn_APPLY.state(:disabled)
@btn_CANCEL.state(:disabled)
end
# apply is just "writesettings"
def apply
writesettings
@btn_APPLY.state(:disabled)
@btn_CANCEL.state(:disabled)
end
#
# Read current settings
#
def readsettings
xfd = open("|xset q", 'r')
xfd.readlines.each{|line|
fields = line.chomp.strip.split(/\s+/)
case fields[0]
when "auto"
if fields[1] == 'repeat:'
@kbdrep = fields[2]
@w_kbdrep.set(@kbdrep)
@kbdcli = fields[6]
end
when "bell"
@bellvol = fields[2]
@bellpit = fields[5]
@belldur = fields[8]
when "acceleration:"
@mouseacc = fields[1]
@mousethr = fields[3]
when "prefer"
if fields[2] == 'yes'
@screenbla = 'blank'
else
@screenbla = 'noblank'
end
@w_screenbla.set(@screenbla)
when "timeout:"
@screentim = fields[1]
@screencyc = fields[3]
end
}
xfd.close
end
#
# Write settings into the X server
#
def writesettings
@bellvol = @w_bellvol.get
@bellpit = @w_bellpit.get
@belldur = @w_belldur.get
@kbdrep = @w_kbdrep.get
if @kbdrep == 'on'
@kbdcli = @w_kbdcli.get
else
@kbdcli = 'off'
end
@mouseacc = @w_mouseacc.get
@mousethr = @w_mousethr.get
@screentim = @w_screentim.get
@screencyc = @w_screencyc.get
@screenbla = @w_screenbla.get
system("xset \
b #{@bellvol} #{@bellpit} #{@belldur} \
c #{@kbdcli} \
r #{@kbdrep} \
m #{@mouseacc} #{@mousethr} \
s #{@screentim} #{@screencyc} \
s #{@screenbla}")
end
#
# Sends all settings to the window
#
def dispsettings
@w_bellvol.set(@bellvol)
@w_bellpit.set(@bellpit)
@w_belldur.set(@belldur)
@w_kbdonoff.set(@w_kbdrep.get)
@w_kbdcli.set(@kbdcli)
@w_mouseacc.set(@mouseacc)
@w_mousethr.set(@mousethr)
@w_screenblank.set(@w_screenbla.get)
@w_screenpat.set(@w_screenbla.get)
@w_screentim.set(@screentim)
@w_screencyc.set(@screencyc)
end
#
# Create all windows, and pack them
#
class LabelEntry
def initialize(parent, text, length, range=[])
@frame = TkFrame.new(parent)
TkLabel.new(@frame, 'text'=>text).pack('side'=>'left')
if range.size > 0
@entry = TkSpinbox.new(@frame, 'width'=>length, 'relief'=>'sunken',
'from'=>range[0], 'to'=>range[1])
else
@entry = TkEntry.new(@frame, 'width'=>length, 'relief'=>'sunken')
end
@entry.pack('side'=>'right','expand'=>'y', 'fill'=>'x')
end
def epath
@frame
end
def pack(keys)
@frame.pack(keys)
end
def get
@entry.value
end
def set(value)
@entry.delete(0,'end')
@entry.insert(0, value)
end
end
def createwindows
win = self
#
# Buttons
#
btn_frame = TkFrame.new(@root)
buttons = [
@btn_OK = TkButton.new(btn_frame, 'command'=>proc{win.ok},
'default'=>'active', 'text'=>'了解'),
@btn_APPLY = TkButton.new(btn_frame, 'command'=>proc{win.writesettings},
'default'=>'normal', 'text'=>'適用',
'state'=>'disabled'),
@btn_CANCEL = TkButton.new(btn_frame, 'command'=>proc{win.cancel},
'default'=>'normal', 'text'=>'取消',
'state'=>'disabled'),
@btn_QUIT = TkButton.new(btn_frame, 'command'=>proc{win.quit},
'default'=>'normal', 'text'=>'中止')
]
buttons.each{|b| b.pack('side'=>'left', 'expand'=>'yes', 'pady'=>5) }
@root.bind('Return', proc{@btn_OK.flash; @btn_OK.invoke})
@root.bind('Escape', proc{@btn_QUIT.flash; @btn_QUIT.invoke})
@root.bind('1', proc{|w|
unless buttons.index(w)
@btn_APPLY.state(:normal)
@btn_CANCEL.state(:normal)
end
}, '%W')
@root.bind('Key', proc{|w, k|
unless buttons.index(w)
case k
when 'Return', 'Escape', 'Tab', /.*Shift.*/
# do nothing
else
@btn_APPLY.state(:normal)
@btn_CANCEL.state(:normal)
end
end
}, '%W %K')
#
# Bell settings
#
bell = TkLabelframe.new(@root, 'text'=>'ベル設定',
'padx'=>'1.5m', 'pady'=>'1.5m')
@w_bellvol = TkScale.new(bell, 'from'=>0, 'to'=>100, 'length'=>200,
'tickinterval'=>20, 'orient'=>'horizontal',
'label'=>"音量 (%)")
f = TkFrame.new(bell)
@w_bellpit = LabelEntry.new(f, "音程 (Hz)", 6, [25, 20000])
@w_bellpit.pack('side'=>'left', 'padx'=>5)
@w_belldur = LabelEntry.new(f, "持続時間 (ms)", 6, [1, 10000])
@w_belldur.pack('side'=>'right', 'padx'=>5)
@w_bellvol.pack('side'=>'top', 'expand'=>'yes')
f.pack('side'=>'top', 'expand'=>'yes')
#
# Keyboard settings
#
kbdonoff = nil
kbdcli = nil
kbd = TkLabelframe.new(@root, 'text'=>'キーボードリピート設定',
'padx'=>'1.5m', 'pady'=>'1.5m')
f = TkFrame.new(kbd)
@w_kbdonoff = TkCheckButton.new(f, 'text'=>'クリック音あり',
'relief'=>'flat',
'onvalue'=>'on', 'offvalue'=>'off',
'variable'=>@w_kbdrep ) {
def self.set(value)
if value == 'on'
self.select
else
self.deselect
end
end
pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x', 'padx'=>[0, '1m'])
}
@w_kbdcli = TkScale.new(f, 'from'=>0, 'to'=>100, 'length'=>200,
'tickinterval'=>20, 'orient'=>'horizontal',
'label'=>'クリック音量 (%)')
@w_kbdcli.pack('side'=>'left', 'expand'=>'yes',
'fill'=>'x', 'padx'=>['1m', 0])
f.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'fill'=>'x')
#
# Mouse settings
#
mouse = TkLabelframe.new(@root, 'text'=>'マウス設定',
'padx'=>'1.5m', 'pady'=>'1.5m')
f = TkFrame.new(mouse)
@w_mouseacc = LabelEntry.new(f, '加速量', 5)
@w_mouseacc.pack('side'=>'left', 'padx'=>[0, '1m'])
@w_mousethr = LabelEntry.new(f, '閾値 (pixels)', 3, [1, 2000])
@w_mousethr.pack('side'=>'right', 'padx'=>['1m', 0])
f.pack('side'=>'top', 'expand'=>'yes')
#
# Screen Saver settings
#
screen = TkLabelframe.new(@root, 'text'=>'スクリーンセーバ設定',
'padx'=>'1.5m', 'pady'=>'1.5m')
@w_screenblank = TkRadioButton.new(screen, 'text'=>'ブランク表示',
'relief'=>'flat', 'anchor'=>'w',
'variable'=>@w_screenbla,
'value'=>'blank') {
def self.set(value)
if value == 'blank'
self.select
else
self.deselect
end
end
}
@w_screenpat = TkRadioButton.new(screen, 'text'=>'パターン表示',
'relief'=>'flat', 'anchor'=>'w',
'variable'=>@w_screenbla,
'value'=>'noblank') {
def self.set(value)
if value != 'blank'
self.select
else
self.deselect
end
end
}
@w_screentim = LabelEntry.new(screen, 'タイムアウト (s)', 5, [1, 100000])
@w_screencyc = LabelEntry.new(screen, '周期 (s)', 5, [1, 100000])
Tk.grid(@w_screenblank, @w_screentim, 'sticky'=>'e')
Tk.grid(@w_screenpat, @w_screencyc, 'sticky'=>'e')
TkGrid.configure(@w_screenblank, @w_screenpat, 'sticky'=>'ew')
#
# Main window
#
param = {
'side'=>'top', 'fill'=>'both', 'expand'=>'yes',
'padx'=>'1m', 'pady'=>'1m'
}
btn_frame.pack('side'=>'top', 'fill'=>'both')
bell.pack(param)
kbd.pack(param)
mouse.pack(param)
screen.pack(param)
#
# Let the user resize our window
#
@root.minsize(10,10)
end
def initialize(title)
@root = TkRoot.new('title'=>title)
@kbdrep = 'on'
@w_kbdrep = TkVariable.new(@kbdrep)
def @w_kbdrep.get
self.value
end
def @w_kbdrep.set(val)
self.value=val
end
@kbdcli = 0
@bellvol = 100
@bellpit = 440
@belldur = 100
@mouseacc = "3/1"
@mousethr = 4
@screenbla = "blank"
@w_screenbla = TkVariable.new(@screenbla)
def @w_screenbla.get
self.value
end
def @w_screenbla.set(val)
self.value=val
end
@screentim = 600
@screencyc = 600
#
# Listen what "xset" tells us...
#
readsettings
#
# Create all windows
#
createwindows
#
# Write xset parameters
#
dispsettings
end
end
Xsettings.new(File.basename($0,'.rb'))
Tk.mainloop
|