2003-08-02 17:39:23 -04:00
|
|
|
#!/usr/bin/env ruby
|
2011-09-14 13:25:37 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
2003-08-02 17:39:23 -04:00
|
|
|
#
|
|
|
|
# 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')
|
2011-05-22 05:26:02 -04:00
|
|
|
if range.size > 0
|
|
|
|
@entry = TkSpinbox.new(@frame, 'width'=>length, 'relief'=>'sunken',
|
2003-08-02 17:39:23 -04:00
|
|
|
'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)
|
2011-05-22 05:26:02 -04:00
|
|
|
buttons = [
|
|
|
|
@btn_OK = TkButton.new(btn_frame, 'command'=>proc{win.ok},
|
2011-09-14 13:25:37 -04:00
|
|
|
'default'=>'active', 'text'=>'了解'),
|
2011-05-22 05:26:02 -04:00
|
|
|
@btn_APPLY = TkButton.new(btn_frame, 'command'=>proc{win.writesettings},
|
2011-09-14 13:25:37 -04:00
|
|
|
'default'=>'normal', 'text'=>'適用',
|
2003-08-02 17:39:23 -04:00
|
|
|
'state'=>'disabled'),
|
2011-05-22 05:26:02 -04:00
|
|
|
@btn_CANCEL = TkButton.new(btn_frame, 'command'=>proc{win.cancel},
|
2011-09-14 13:25:37 -04:00
|
|
|
'default'=>'normal', 'text'=>'取消',
|
2003-08-02 17:39:23 -04:00
|
|
|
'state'=>'disabled'),
|
2011-05-22 05:26:02 -04:00
|
|
|
@btn_QUIT = TkButton.new(btn_frame, 'command'=>proc{win.quit},
|
2011-09-14 13:25:37 -04:00
|
|
|
'default'=>'normal', 'text'=>'中止')
|
2003-08-02 17:39:23 -04:00
|
|
|
]
|
|
|
|
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
|
|
|
|
#
|
2011-09-14 13:25:37 -04:00
|
|
|
bell = TkLabelframe.new(@root, 'text'=>'ベル設定',
|
2003-08-02 17:39:23 -04:00
|
|
|
'padx'=>'1.5m', 'pady'=>'1.5m')
|
2011-05-22 05:26:02 -04:00
|
|
|
@w_bellvol = TkScale.new(bell, 'from'=>0, 'to'=>100, 'length'=>200,
|
|
|
|
'tickinterval'=>20, 'orient'=>'horizontal',
|
2011-09-14 13:25:37 -04:00
|
|
|
'label'=>"音量 (%)")
|
2003-08-02 17:39:23 -04:00
|
|
|
|
|
|
|
f = TkFrame.new(bell)
|
2011-09-14 13:25:37 -04:00
|
|
|
@w_bellpit = LabelEntry.new(f, "音程 (Hz)", 6, [25, 20000])
|
2003-08-02 17:39:23 -04:00
|
|
|
@w_bellpit.pack('side'=>'left', 'padx'=>5)
|
2011-09-14 13:25:37 -04:00
|
|
|
@w_belldur = LabelEntry.new(f, "持続時間 (ms)", 6, [1, 10000])
|
2003-08-02 17:39:23 -04:00
|
|
|
@w_belldur.pack('side'=>'right', 'padx'=>5)
|
|
|
|
|
|
|
|
@w_bellvol.pack('side'=>'top', 'expand'=>'yes')
|
|
|
|
f.pack('side'=>'top', 'expand'=>'yes')
|
|
|
|
|
|
|
|
#
|
|
|
|
# Keyboard settings
|
2011-05-22 05:26:02 -04:00
|
|
|
#
|
2003-08-02 17:39:23 -04:00
|
|
|
kbdonoff = nil
|
|
|
|
kbdcli = nil
|
2011-09-14 13:25:37 -04:00
|
|
|
kbd = TkLabelframe.new(@root, 'text'=>'キーボードリピート設定',
|
2003-08-02 17:39:23 -04:00
|
|
|
'padx'=>'1.5m', 'pady'=>'1.5m')
|
|
|
|
f = TkFrame.new(kbd)
|
2011-09-14 13:25:37 -04:00
|
|
|
@w_kbdonoff = TkCheckButton.new(f, 'text'=>'クリック音あり',
|
2011-05-22 05:26:02 -04:00
|
|
|
'relief'=>'flat',
|
2003-08-02 17:39:23 -04:00
|
|
|
'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'])
|
|
|
|
}
|
2011-05-22 05:26:02 -04:00
|
|
|
@w_kbdcli = TkScale.new(f, 'from'=>0, 'to'=>100, 'length'=>200,
|
|
|
|
'tickinterval'=>20, 'orient'=>'horizontal',
|
2011-09-14 13:25:37 -04:00
|
|
|
'label'=>'クリック音量 (%)')
|
2011-05-22 05:26:02 -04:00
|
|
|
@w_kbdcli.pack('side'=>'left', 'expand'=>'yes',
|
2003-08-02 17:39:23 -04:00
|
|
|
'fill'=>'x', 'padx'=>['1m', 0])
|
|
|
|
f.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'fill'=>'x')
|
|
|
|
|
|
|
|
#
|
|
|
|
# Mouse settings
|
|
|
|
#
|
2011-09-14 13:25:37 -04:00
|
|
|
mouse = TkLabelframe.new(@root, 'text'=>'マウス設定',
|
2003-08-02 17:39:23 -04:00
|
|
|
'padx'=>'1.5m', 'pady'=>'1.5m')
|
|
|
|
f = TkFrame.new(mouse)
|
2011-09-14 13:25:37 -04:00
|
|
|
@w_mouseacc = LabelEntry.new(f, '加速量', 5)
|
2003-08-02 17:39:23 -04:00
|
|
|
@w_mouseacc.pack('side'=>'left', 'padx'=>[0, '1m'])
|
2011-09-14 13:25:37 -04:00
|
|
|
@w_mousethr = LabelEntry.new(f, '閾値 (pixels)', 3, [1, 2000])
|
2003-08-02 17:39:23 -04:00
|
|
|
@w_mousethr.pack('side'=>'right', 'padx'=>['1m', 0])
|
|
|
|
f.pack('side'=>'top', 'expand'=>'yes')
|
|
|
|
|
|
|
|
#
|
|
|
|
# Screen Saver settings
|
|
|
|
#
|
2011-09-14 13:25:37 -04:00
|
|
|
screen = TkLabelframe.new(@root, 'text'=>'スクリーンセーバ設定',
|
2003-08-02 17:39:23 -04:00
|
|
|
'padx'=>'1.5m', 'pady'=>'1.5m')
|
2011-09-14 13:25:37 -04:00
|
|
|
@w_screenblank = TkRadioButton.new(screen, 'text'=>'ブランク表示',
|
2011-05-22 05:26:02 -04:00
|
|
|
'relief'=>'flat', 'anchor'=>'w',
|
|
|
|
'variable'=>@w_screenbla,
|
2003-08-02 17:39:23 -04:00
|
|
|
'value'=>'blank') {
|
|
|
|
def self.set(value)
|
|
|
|
if value == 'blank'
|
|
|
|
self.select
|
|
|
|
else
|
|
|
|
self.deselect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2011-09-14 13:25:37 -04:00
|
|
|
@w_screenpat = TkRadioButton.new(screen, 'text'=>'パターン表示',
|
2011-05-22 05:26:02 -04:00
|
|
|
'relief'=>'flat', 'anchor'=>'w',
|
|
|
|
'variable'=>@w_screenbla,
|
2003-08-02 17:39:23 -04:00
|
|
|
'value'=>'noblank') {
|
|
|
|
def self.set(value)
|
|
|
|
if value != 'blank'
|
|
|
|
self.select
|
|
|
|
else
|
|
|
|
self.deselect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2011-09-14 13:25:37 -04:00
|
|
|
@w_screentim = LabelEntry.new(screen, 'タイムアウト (s)', 5, [1, 100000])
|
|
|
|
@w_screencyc = LabelEntry.new(screen, '周期 (s)', 5, [1, 100000])
|
2003-08-02 17:39:23 -04:00
|
|
|
|
|
|
|
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 = {
|
2011-05-22 05:26:02 -04:00
|
|
|
'side'=>'top', 'fill'=>'both', 'expand'=>'yes',
|
2003-08-02 17:39:23 -04:00
|
|
|
'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
|