summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-04-26 12:37:23 +0200
committerMattias Andrée <maandree@operamail.com>2014-04-26 12:37:23 +0200
commit04181e696f73f793046a22acdf64d34dd1099092 (patch)
tree1152471508e746a9999996e602abfc3c9dcaf99b
parentfix makefile error (diff)
downloadblueshift-04181e696f73f793046a22acdf64d34dd1099092.tar.gz
blueshift-04181e696f73f793046a22acdf64d34dd1099092.tar.bz2
blueshift-04181e696f73f793046a22acdf64d34dd1099092.tar.xz
m + add x-window-focus
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile10
-rw-r--r--TODO3
-rw-r--r--examples/bedtime2
-rw-r--r--examples/comprehensive6
-rw-r--r--examples/darkroom2
-rw-r--r--examples/sleepmode2
-rw-r--r--examples/x-window-focus170
-rw-r--r--info/blueshift.texinfo8
8 files changed, 189 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index c6a29e3..5f69e33 100644
--- a/Makefile
+++ b/Makefile
@@ -91,15 +91,15 @@ FLAGS = $$($(PKGCONFIG) --cflags $(LIBS)) -std=$(STD) $(WARN) $(OPTIMISE) -fPIC
# Resource files
DATAFILES = 2deg 10deg redshift redshift_old
# Python source files
-PYFILES = __main__.py colour.py curve.py monitor.py solar.py icc.py adhoc.py \
+PYFILES = __main__.py colour.py curve.py monitor.py solar.py icc.py adhoc.py \
backlight.py blackbody.py aux.py weather.py interpolation.py
# Library files
CBINDINGS = $(foreach B,$(SERVER_BINDINGS),blueshift_$(B).so)
# Configuration script example files
-EXAMPLES = comprehensive sleepmode crtc-detection crtc-searching logarithmic \
- xmobar xpybar stored-settings current-settings xmonad threaded \
- backlight darkroom textconf textconf.conf modes weather battery \
- icc-profile-atoms bedtime
+EXAMPLES = comprehensive sleepmode crtc-detection crtc-searching logarithmic \
+ xmobar xpybar stored-settings current-settings xmonad threaded \
+ backlight darkroom textconf textconf.conf modes weather battery \
+ icc-profile-atoms bedtime x-window-focus
# Build rules
diff --git a/TODO b/TODO
index 6014ee8..e493820 100644
--- a/TODO
+++ b/TODO
@@ -20,9 +20,6 @@ Low priority:
(Not too important, it is hardcoded in X to only allow 256)
Use Robertson's method
Screen count function for VidMode should be added
- Make an example that can, using just X, change settings
- depending on what window is in focus or visible on a
- monitor.
Future stuff:
How is it looking on the DirectFB front?
diff --git a/examples/bedtime b/examples/bedtime
index 23ebec9..8f2da94 100644
--- a/examples/bedtime
+++ b/examples/bedtime
@@ -56,7 +56,7 @@ time_wakeup_saturday = ('13:00', '14:00')
time_wakeup_sunday = ('13:00', '14:00')
-# The (zero-based) index of the monitors (CRTC:s) to apply
+# The (zero-based) indices of the monitors (CRTC:s) to apply
# settings to. An empty list means that all monitors are used,
# but all monitors will have the same settings.
monitors = []
diff --git a/examples/comprehensive b/examples/comprehensive
index 14a62b6..be5361f 100644
--- a/examples/comprehensive
+++ b/examples/comprehensive
@@ -91,8 +91,8 @@ download_command = None
# Method for applying colour curves in X.
-#apply_curves_x = randr
-apply_curves_x = vidmode
+apply_curves_x = randr
+#apply_curves_x = vidmode
# Method for applying colour curves in TTY.
apply_curves_tty_ = drm
@@ -173,7 +173,7 @@ weather_modifiers = { 'clear' : 1.00
visibility_max = 4
-# The (zero-based) index of the monitors (CRTC:s) to apply
+# The (zero-based) indices of the monitors (CRTC:s) to apply
# settings to. An empty list means that all monitors are used,
# but all monitors will have the same settings.
monitors = []
diff --git a/examples/darkroom b/examples/darkroom
index d1647bc..65d9f3d 100644
--- a/examples/darkroom
+++ b/examples/darkroom
@@ -21,7 +21,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# The (zero-based) index of the monitors (CRTC:s) to apply
+# The (zero-based) indices of the monitors (CRTC:s) to apply
# settings to. An empty list means that all monitors are used,
# but all monitors will have the same settings.
monitors = []
diff --git a/examples/sleepmode b/examples/sleepmode
index d633f27..26686e8 100644
--- a/examples/sleepmode
+++ b/examples/sleepmode
@@ -21,7 +21,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# The (zero-based) index of the monitors (CRTC:s) to apply
+# The (zero-based) indices of the monitors (CRTC:s) to apply
# settings to. An empty list means that all monitors are used,
# but all monitors will have the same settings.
monitors = []
diff --git a/examples/x-window-focus b/examples/x-window-focus
new file mode 100644
index 0000000..777659d
--- /dev/null
+++ b/examples/x-window-focus
@@ -0,0 +1,170 @@
+# -*- python -*-
+
+# This configuration scripts can change the adjustment settings
+# depending on that window is in focus, by class or title.
+# However this is actually Window Manager dependent and have
+# only been tested on twm and xmonad.
+
+
+# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+#
+# 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 program 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/>.
+
+
+# This requires that python3-xlib is installed.
+
+
+import Xlib.display
+
+
+# The (zero-based) indices of the monitors
+# (CRTC:s) to apply settings to
+monitors = [0, 1]
+
+# Gamma (red, green and blue), per monitor
+gammas = [[1.16, 1.15, 1.11],
+ [1.10, 1.16, 1.10]]
+
+# The colour temperature for normal programs
+standard_temperature = 3500
+
+# Acquire connection to X
+x_display = Xlib.display.Display()
+# Get root windows for each screen and list on most events
+mask = ((1 << 2) - 1) ^ ((1 << 0) - 1)
+mask |= ((1 << 14) - 1) ^ ((1 << 3) - 1)
+mask |= ((1 << 20) - 1) ^ ((1 << 15) - 1)
+mask |= ((1 << 25) - 1) ^ ((1 << 21) - 1)
+for x_screen_i in range(x_display.screen_count()):
+ x_screen = x_display.screen(x_screen_i)
+ x_root = x_screen.root
+ x_root.change_attributes(event_mask = mask)
+x_display.flush()
+
+# Close X connection on exit
+close_c_bindings_ = close_c_bindings
+def close_c_bindings():
+ close_c_bindings_()
+ x_display.close()
+
+
+def reset():
+ '''
+ Invoked to reset the displays
+ '''
+ for monitor in range(len(monitors)):
+ start_over()
+ gamma(*gammas[monitor])
+ randr(monitors[monitor])
+
+
+wait_period = 0
+'''
+:float The number of seconds to wait before invoking `periodically` again
+'''
+
+fadein_time = None
+'''
+:float? The number of seconds used to fade in on start, `None` for no fading
+'''
+
+fadeout_time = None
+'''
+:float? The number of seconds used to fade out on exit, `None` for no fading
+'''
+
+
+last = None
+def periodically(year, month, day, hour, minute, second, weekday, fade):
+ '''
+ Invoked periodically
+
+ If you want to control at what to invoke this function next time
+ you can set the value of the global variable `wait_period` to the
+ number of seconds to wait before invoking this function again.
+ The value does not need to be an integer.
+
+ @param year:int The year
+ @param month:int The month, 1 = January, 12 = December
+ @param day:int The day, minimum value is 1, probable maximum value is 31 (*)
+ @param hour:int The hour, minimum value is 0, maximum value is 23
+ @param minute:int The minute, minimum value is 0, maximum value is 59
+ @param second:int The second, minimum value is 0, probable maximum value is 60 (**)
+ @param weekday:int The weekday, 1 = Monday, 7 = Sunday
+ @param fade:float? Blueshift can use this function to fade into a state when it start
+ or exits. `fade` can either be negative, zero or positive or `None`,
+ but the magnitude of value cannot exceed 1. When Blueshift starts,
+ the this function will be invoked multiple with the time parameters
+ of the time it is invoked and each time `fade` will increase towards
+ 1, starting at 0, when the value is 1, the settings should be applied
+ to 100 %. After this this function will be invoked once again with
+ `fade` being `None`. When Blueshift exits the same behaviour is used
+ except, `fade` decrease towards -1 but start slightly below 0, when
+ -1 is reached all settings should be normal. Then Blueshift will NOT
+ invoke this function with `fade` being `None`, instead it will by
+ itself revert all settings and quit.
+
+ (*) Can be exceeded if the calendar system is changed, like in 1712-(02)Feb-30
+ (**) See https://en.wikipedia.org/wiki/Leap_second
+ '''
+ global last
+
+ try:
+ # Get focused window
+ window = x_display.get_input_focus().focus
+ if isinstance(window, int):
+ x_display.next_event()
+ return
+
+ # Get window specifications
+ wm_class = window.get_wm_class()
+ wm_name = window.get_wm_name()
+ if (wm_class is None) and (wm_name is None):
+ x_display.next_event()
+ return
+ if (wm_name is not None) and (not isinstance(wm_name, str)):
+ wm_name = wm_name.decode('utf-8', 'replace')
+ window = (None if wm_class is None else wm_class[0],
+ None if wm_class is None else wm_class[1],
+ wm_name)
+ #print(window)
+ except:
+ x_display.next_event()
+ return
+
+ # Check that something changed
+ if (last is not None) and (last == window):
+ x_display.next_event()
+ return
+ last = window
+
+ # Update adjustments
+ for monitor in range(len(monitors)):
+ start_over()
+ temp = standard_temperature
+
+ if window[0] in ('Dooble', 'claws-mail'):
+ temp = 2000
+ elif window[0] == 'inkscape':
+ temp = 6500
+ elif window[0].startswith('gimp-'): # continues with the version number
+ temp = 6500
+
+ temperature(temp, lambda t : clip_whitepoint(divide_by_maximum(cmf_10deg(t))))
+ gamma(*gammas[monitor])
+ randr(monitors[monitor])
+
+ # Wait for next update
+ x_display.next_event()
+
diff --git a/info/blueshift.texinfo b/info/blueshift.texinfo
index 6c3160a..86783d0 100644
--- a/info/blueshift.texinfo
+++ b/info/blueshift.texinfo
@@ -2119,6 +2119,14 @@ multithreaded configurations script.
This is a samll example demonstrates how to include
weather conditions in your configuration scripts.
+@item x-window-focus
+This example can be used (hopefully@footnote{It has
+been tested on xmonad and twm, and the feature is
+window manager dependent}) any X window manager.
+It identifies what window is in focus, by class
+@footnote{Class is almost the same thing as application.}
+or title, and applies appropriate adjustments.
+
@item xmobar
This example can be used in @command{xmobar} to display
the Sun's elevation and to what degree it is day time.