forked from harmattan/camerra
/
camerra.py
74 lines (58 loc) · 2.28 KB
/
camerra.py
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
#
# Ye Olde Camerra Hack - Another fine Harmattan Hack Powered by Python(tm)!
# 2012-01-12; Thomas Perl <thp.io/about>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# On Debian systems, the complete text of the GNU General
# Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
#
from QmSystem import *
from PySide.QtGui import *
from PySide.QtDeclarative import *
import sys
import subprocess
import re
import time
app = QApplication(sys.argv)
keys = QmKeys()
last_time = time.time()
WAIT_BETWEEN_CLICKS = 3
WINID_REGEX = r'_NET_ACTIVE_WINDOW\(WINDOW\): window id # (0x[0-9a-f]*)'
CAMERA_REGEX = r'WM_CLASS\(STRING\) = "camera-ui"'
def camera_app_on_top():
# Is the window of the camera app currently on top or some other app?
root = subprocess.Popen(['xprop', '-root'], stdout=subprocess.PIPE)
stdout, stderr = root.communicate()
win_id = re.search(WINID_REGEX, stdout).group(1)
win_info = subprocess.Popen(['xprop', '-id', win_id],
stdout=subprocess.PIPE)
stdout, stderr = win_info.communicate()
return re.search(CAMERA_REGEX, stdout) is not None
def keyEvent(key, state):
# Callback for QmKeys key events
global last_time
if time.time() - last_time < WAIT_BETWEEN_CLICKS:
# Avoid hammering the cam app when Vol+ is being kept pressed
return
if key == state == 2 and camera_app_on_top():
last_time = time.time()
p = subprocess.Popen(['xresponse', '-d', '820x240,820x240', '-w', '1'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
keys.keyEvent.connect(keyEvent)
view = QDeclarativeView()
view.setSource('/opt/camerra/camerra.qml')
view.showFullScreen()
app.exec_()