Initial Commit
[packages] / xemacs-packages / xwem / lisp / xwem-gamma.el
1 ;;; xwem-gamma.el --- XWEM addon used to adjust gamma.
2
3 ;; Copyright (C) 2004,2005 by XWEM Org.
4
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
6 ;;         Steve Youngs  <steve@youngs.au.com>
7 ;; Created: Tue Jan 20 13:10:28 MSK 2004
8 ;; Keywords: xwem
9 ;; X-CVS: $Id: xwem-gamma.el,v 1.7 2005-04-04 19:54:12 lg Exp $
10
11 ;; This file is part of XWEM.
12
13 ;; XWEM is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; XWEM is distributed in the hope that it will be useful, but WITHOUT
19 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
21 ;; License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 ;; 02111-1307, USA.
27
28 ;;; Synched up with: Not in FSF
29
30 ;;; Commentary:
31
32 ;; `xwem-gamma' uses uses `xlib-vidmode' Xlib extension and
33 ;; `color-selector' package.
34
35 ;; To use it do something like:
36 ;;
37 ;;     (xwem-gamma-widget (xwem-dpy))
38
39 ;;; Code:
40 \f
41 (require 'xlib-vidmode)
42 (require 'color-selector)
43
44 (require 'xwem-load)
45 (require 'xwem-misc)
46
47 (defface xwem-gamma-face
48   `((t (:foreground "#1a1a1a" :background "black")))
49   "Face used to adjust gamma.")
50
51 (defvar xwem-gamma-display nil
52   "X Display.")
53
54 (defvar xwem-gamma-screen 0
55   "Screen number.")
56
57 \f
58 ;;; Functions
59 (defun xwem-gamma-corector (selector)
60   "Using SELECTOR adjust gamma."
61   (let* ((k (/ 9.9 256))
62          (clist (color-selector-get-color selector))
63          (rg (+ 0.1 (* k (car clist))))
64          (gg (+ 0.1 (* k (cadr clist))))
65          (bg (+ 0.1 (* k (caddr clist)))))
66     (X-XF86VidModeSetGamma xwem-gamma-display rg gg bg xwem-gamma-screen)
67     (XFlush xwem-gamma-display)
68     (xwem-message 'nolog "New gamma: r=%f g=%f b=%f" rg gg bg)))
69
70 (defun xwem-gamma-widget (xdpy &optional screen-num)
71   "Start correcting gama on display XDPY and screen SCREEN-NUM."
72   (setq xwem-gamma-display xdpy)
73   (setq xwem-gamma-screen (or (and (numberp screen-num) screen-num) 0))
74   (color-selector-make-selector 'xwem-gamma-face 'foreground
75                                 'xwem-gamma-corector))
76
77 \f
78 (provide 'xwem-gamma)
79
80 ;;; xwem-gamma.el ends here