Felix 弄来一只 Apple Magic Mouse 小白, 蓝牙配对上后发现各种scrolling很靠谱, 三键也支持好了, 但是多指动作没有支持…
在各种Google之后, 找到了有人使用 PyMT 来实现 Magic Mouse 多点触控手势的脚本, 由于原脚本(参考资料1)是针对GNOME/compiz的, 而且网上没有靠谱的KDE可用版本, 于是本猫自己Hack了一下…
安装说明:
首先要安装pymt, ArchLinux用户可以直接
yaourt -S pymt
Ubuntu用户可以直接
sudo apt-get install python-pymt
接下来, 配置pymt识别MagicMouse的多点触控:
编辑 ~/.pymt/config
找到 [input] 段, 修改为:
[input]
default = hidinput,/dev/input/event
上面的<n>需要替换成MagicMouse对应的编号, 可以用下面这个本猫写的挫挫的语句察看:
cat /var/log/Xorg.0.log|grep udev|grep -i apple|grep /dev/input/event
然后, 给这个文件(设备?信号?事件? = =不知道怎么称呼了)加上读属性, 以使得pymt可以用当前用户身份读取:
sudo chmod a+r `cat /var/log/Xorg.0.log|grep udev|grep -i apple|grep /dev/input/event|sed -e 's/.*\(\/dev\/input[^\)]*\).*/\1/'`
至此, 可以认为pymt安装好啦!
测试:
python -m pymt.tools.demo
(arch用户自行改为python2 = =)
接下来…可以试试我的脚本啦!
— Changelog:
2011/4/19 – 第二个版本, 增加了三指上下调节系统音量的功能~~
2011/4/19 – 第一个版本, 仅简单实现了双指Swipe Left/Right 切换虚拟桌面的效果.
#!/usr/bin/env python2
from pymt import *
import sys, dbus, subprocess, os
import time
class Tracer(MTWidget):
SWIPE_X_THRESHOLD = 120
SWIPE_Y_THRESHOLD = 50
LEFT_SWIPE, RIGHT_SWIPE = range(2)
block = False
def run_cmd(self, cmd):
return subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).communicate()[0]
def dbus_message(self, action):
try:
rootwin = subprocess.Popen(['xwininfo', '-root'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
except OSError:
raise SystemExit('Error: xwininfo not present')
try:
rootwin_id = int(rootwin.split()[3], 0)
except IndexError:
raise SystemExit('Error: unexpectedly short output from xwininfo')
except ValueError:
raise SystemExit('Error: unable to convert "%s" to int', rootwin.split()[3])
session_bus = dbus.SessionBus()
args = ['root', rootwin_id]
kwin = session_bus.get_object('org.kde.kwin', '/KWin')
exec('kwin.' + action + '()')
def on_touch_move(self, touch):
#if touch.y < 150:
# return
#if touch.x < 100 or touch.x > 600:
# return
if self.block:
return
if len(getCurrentTouches()) == 3:
if (touch.y - touch.oypos) < -self.SWIPE_Y_THRESHOLD:
self.block = True
currentvolumn = int(self.run_cmd(r'amixer -c 0 get Master|grep -i left|grep %|sed -e "s/.*\[\([0-9]*\)%\].*/\1/"'))
self.run_cmd('amixer -c 0 sset Master,0 %d' % (currentvolumn - 5, ) + '%')
return
if (touch.y - touch.oypos) > self.SWIPE_Y_THRESHOLD:
self.block = True
currentvolumn = int(self.run_cmd(r'amixer -c 0 get Master|grep -i left|grep %|sed -e "s/.*\[\([0-9]*\)%\].*/\1/"'))
self.run_cmd('amixer -c 0 sset Master,0 %d' % (currentvolumn + 5, ) + '%')
return
if len(getCurrentTouches()) == 2:
if (touch.x - touch.oxpos) > self.SWIPE_X_THRESHOLD:
self.block = True
self.dbus_message("previousDesktop")
return
elif (touch.x - touch.oxpos) < -self.SWIPE_X_THRESHOLD:
self.block = True
self.dbus_message("nextDesktop")
return
def on_touch_up(self, touch):
self.block = False
runTouchApp(Tracer())
很简单哟~快来自定义属于自己的快捷键吧^_^
参考资料:
1, https://gist.github.com/546779
2, http://ubuntuforums.org/archive/index.php/t-1386790.html
3, http://pymt.eu/wiki/DevGuide/InstallPymtUbuntu
4, http://pymt.eu/wiki/DevGuide/InputConfiguration
5, http://pymt.eu/wiki/DevGuide/ConfigurationFile
python -m pymt.tools.demo
[INFO ] PyMT v0.5.1
[WARNING] [Core ] Accelerate module not available
[INFO ] [Logger ] Record log in /home/qianlnk/.pymt/logs/pymt_16-09-22_10.txt
[WARNING] [Core ] Execute “python setup.py build_ext–inplace”
[INFO ] [No OpenGL_accelerate module loaded] No module named OpenGL_accelerate
[INFO ] [Unable to load registered array format handler numeric]
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/OpenGL/arrays/formathandler.py”, line 35, in loadPlugin
plugin_class = entrypoint.load()
File “/usr/lib/python2.7/dist-packages/OpenGL/plugins.py”, line 14, in load
return importByName( self.import_path )
File “/usr/lib/python2.7/dist-packages/OpenGL/plugins.py”, line 28, in importByName
module = __import__( “.”.join(moduleName), {}, {}, moduleName)
File “/usr/lib/python2.7/dist-packages/OpenGL/arrays/numeric.py”, line 15, in
raise ImportError( “””No Numeric module present: %s”””%(err))
ImportError: No Numeric module present: No module named Numeric
[INFO ] [Unable to load registered array format handler vbo]
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/OpenGL/arrays/formathandler.py”, line 35, in loadPlugin
plugin_class = entrypoint.load()
File “/usr/lib/python2.7/dist-packages/OpenGL/plugins.py”, line 14, in load
return importByName( self.import_path )
File “/usr/lib/python2.7/dist-packages/OpenGL/plugins.py”, line 28, in importByName
module = __import__( “.”.join(moduleName), {}, {}, moduleName)
File “/usr/lib/python2.7/dist-packages/OpenGL/arrays/vbo.py”, line 33, in
from OpenGL import GL
ImportError: cannot import name GL
[INFO ] [Unable to load registered array format handler vbooffset]
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/OpenGL/arrays/formathandler.py”, line 35, in loadPlugin
plugin_class = entrypoint.load()
File “/usr/lib/python2.7/dist-packages/OpenGL/plugins.py”, line 14, in load
return importByName( self.import_path )
File “/usr/lib/python2.7/dist-packages/OpenGL/plugins.py”, line 28, in importByName
module = __import__( “.”.join(moduleName), {}, {}, moduleName)
File “/usr/lib/python2.7/dist-packages/OpenGL/arrays/vbo.py”, line 33, in
from OpenGL import GL
ImportError: cannot import name GL
/usr/bin/python: cannot import name GL_TEXTURE_RECTANGLE_NV
fy,有空上一下QQ。想开发一个只统计群邮发言次数和发布资源次数的软件,不统计附件大小。不知是否可行,5.1期间有空没?Deep Blue留~
我的鼠标也寿终正寝的说~….到时候试试~嘿嘿~
都被毒翻了 = =
见佛杀佛啊
= =您明显需要自重…
我显然没有你重~
最上面那位同学,我有好多多余的无线鼠哦~~
这个嵌套可以套多深? 会不会超出页面宽度? 胖猫继续
额 右对齐的呀…
嗯, 必须的, 不可能超出宽度的, 乃就死心吧
那如果到最后只有每行一列了,下一个嵌套肿摸办?
乃可以试试…
嗯,好滴
我来试试能不能超出去2333333
竟然有最小宽度限制눈_눈