aboutsummaryrefslogtreecommitdiffstats
path: root/src/__main__.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-03 23:40:59 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-03 23:40:59 +0100
commitcf19015c665fa067034e94be1fdc315e94bb2b04 (patch)
tree706f660a60243100b282437c77cc8b1e56e46250 /src/__main__.py
parentadd chase (diff)
downloadxpybar-cf19015c665fa067034e94be1fdc315e94bb2b04.tar.gz
xpybar-cf19015c665fa067034e94be1fdc315e94bb2b04.tar.bz2
xpybar-cf19015c665fa067034e94be1fdc315e94bb2b04.tar.xz
add solar information
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/__main__.py')
-rwxr-xr-xsrc/__main__.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/__main__.py b/src/__main__.py
index ace57f9..5c9f831 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -16,6 +16,7 @@ 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/>.
'''
+import Xlib.threaded # IMPORTANT (threading do not work otherwise, see XInitThreads)
import Xlib.display, Xlib.Xatom, Xlib.ext.randr, Xlib.X
from argparser import *
@@ -93,6 +94,7 @@ class Bar:
@variable font_height:int The height of the default font
@variable font_width:int The width of an 'X' with the default font
@variable palette A 16-array of standard colours
+ @variable cmap_cache Custom colour map cache
'''
def __init__(self, output, height, ypos, top, font, background, foreground):
@@ -115,6 +117,7 @@ class Bar:
self.gc = self.window.create_gc()
self.cmap = self.window.get_attributes().colormap
## Graphics variables
+ self.cmap_cache = {}
self.background = self.create_colour(*background)
self.foreground = self.create_colour(*foreground)
(self.font, self.font_metrics, self.font_height) = self.create_font(font)
@@ -311,7 +314,12 @@ class Bar:
@param blue:int The blue component [0, 255]
@return The colour
'''
- return self.cmap.alloc_color(red * 257, green * 257, blue * 257).pixel
+ cid = (red << 16) | (green << 8) | blue
+ if cid in self.cmap_cache:
+ return self.cmap_cache[cid]
+ rc = self.cmap.alloc_color(red * 257, green * 257, blue * 257).pixel
+ self.cmap_cache[cid] = rc
+ return rc
def create_font(self, font):
'''