summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-02-16 19:19:36 +0100
committerMattias Andrée <maandree@operamail.com>2014-02-16 19:19:36 +0100
commita7ab7860a57cdd41944355a400f62581f8b19d03 (patch)
tree532e3e68540102655e16f212386ff1fcf3440e31
parentc binding (diff)
downloadblueshift-a7ab7860a57cdd41944355a400f62581f8b19d03.tar.gz
blueshift-a7ab7860a57cdd41944355a400f62581f8b19d03.tar.bz2
blueshift-a7ab7860a57cdd41944355a400f62581f8b19d03.tar.xz
use randr
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--.gitignore2
-rw-r--r--Makefile10
-rwxr-xr-xsrc/__main__.py4
-rw-r--r--src/blueshift_randr.pyx (renamed from src/_blueshift_randr.pyx)0
-rw-r--r--src/monitor.py23
5 files changed, 32 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 87b68f2..91cb8fb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,5 +10,5 @@ obj/
*.out
*.gch
__pycache__/
-/src/_blueshift_randr.c
+/src/blueshift_randr.c
diff --git a/Makefile b/Makefile
index df938e1..e964aae 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@ FLAGS = $$($(PKGCONFIG) --cflags --libs $(LIBS)) -std=$(STD) $(WARN) $(OPTIMISE)
all: bin/blueshift_randr.so
-bin/blueshift_randr.so: obj/_blueshift_randr.o obj/blueshift_randr_c.o
+bin/blueshift_randr.so: obj/blueshift_randr.o obj/blueshift_randr_c.o
@mkdir -p bin
$(CC) $(FLAGS) -shared -o $@ $^
@@ -23,13 +23,13 @@ obj/%.o: obj/%.c
@mkdir -p obj
$(CC) $(FLAGS) -c -o $@ $<
-obj/_blueshift_randr.c: src/_blueshift_randr.pyx
+obj/blueshift_randr.c: src/blueshift_randr.pyx
@mkdir -p obj
- if ! cython -3 -v $<; then src/_blueshift_randr.c ; false ; fi
- mv src/_blueshift_randr.c $@
+ if ! cython -3 -v $<; then src/blueshift_randr.c ; false ; fi
+ mv src/blueshift_randr.c $@
.PHONY: all
clean:
- -rm -r bin obj src/_blueshift_randr.c
+ -rm -r bin obj src/blueshift_randr.c
diff --git a/src/__main__.py b/src/__main__.py
index 400c675..f8db7a2 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -150,7 +150,6 @@ if config_file is not None:
code = code.decode('utf8', 'error') + '\n'
code = compile(code, file, 'exec')
exec(code, globals)
- break
else:
print('No configuration file found')
sys.exit(1)
@@ -168,6 +167,7 @@ if periodically is not None:
running = False
start_over()
monitor_controller()
+ close_c_bindings()
sys.exit(0)
running = False
signal.signal(signal.SIGTERM, signal_SIGTERM)
@@ -205,3 +205,5 @@ if periodically is not None:
start_over()
monitor_controller()
+close_c_bindings()
+
diff --git a/src/_blueshift_randr.pyx b/src/blueshift_randr.pyx
index e022714..e022714 100644
--- a/src/_blueshift_randr.pyx
+++ b/src/blueshift_randr.pyx
diff --git a/src/monitor.py b/src/monitor.py
index 37f6b00..b8f5cff 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -15,6 +15,15 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import sys
+
+# /usr/lib
+LIBDIR = 'bin'
+sys.path.append(LIBDIR)
+
+from blueshift_randr import *
+randr_opened = False
+
def translate_to_integers():
'''
@@ -31,17 +40,31 @@ def translate_to_integers():
return (R_curve, G_curve, B_curve)
+def close_c_bindings():
+ global randr_opened
+ if randr_opened:
+ randr_close()
+
+
def randr(*crtcs):
'''
Applies colour curves using the X11 extension randr
@param *crtcs The CRT controllers to use, all are used if none are specified
'''
+ global randr_opened
crtcs = sum([1 << i for i in list(crtcs)])
if crtcs == 0:
crtcs = -1;
(R_curve, G_curve, B_curve) = translate_to_integers()
+ if not randr_opened:
+ if randr_open(0) == 0: ## TODO support specifying screen
+ randr_opened = True
+ else:
+ sys.exit(1)
+ if not randr_apply(crtcs, R_curve, G_curve, B_curve) == 0:
+ sys.exit(1)
def print_curves(*crtcs):