Initial Commit
[packages] / xemacs-packages / xlib / lisp / xlib-vidmode.el
1 ;;; xlib-vidmode.el --- XF86VidMode extension support.
2
3 ;; Copyright (C) 2004,2005 by XWEM Org.
4
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
6 ;; Created: Fri Jan 16 18:39:44 MSK 2004
7 ;; Keywords: xlib, xwem
8 ;; X-CVS: $Id: xlib-vidmode.el,v 1.5 2005-04-04 19:55:29 lg Exp $
9
10 ;; This file is part of XWEM.
11
12 ;; XWEM is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; XWEM is distributed in the hope that it will be useful, but WITHOUT
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
20 ;; License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;; 02111-1307, USA.
26
27 ;;; Synched up with: Not in FSF
28
29 ;;; Commentary:
30
31 ;; 
32 ;;; Code:
33 \f
34 (require 'xlib-xlib)
35
36 (defconst X-XF86VidMode-major 2 "Major version of VidMode extension.")
37 (defconst X-XF86VidMode-minor 1 "Minor version of VidMode extension.")
38
39 (defconst X-XF86VidMode-op-QueryVersion 0)
40 (defconst X-XF86VidMode-op-GetModeLine 1 "Opcode to fetch current modeline from server.")
41 (defconst X-XF86VidMode-op-ModModeLine 2)
42 (defconst X-XF86VidMode-op-SwitchMode 3)
43 (defconst X-XF86VidMode-op-GetMonitor 4)
44 (defconst X-XF86VidMode-op-LockModeSwitch 5)
45 (defconst X-XF86VidMode-op-GetAllModeLines 6)
46 (defconst X-XF86VidMode-op-AddModeLine  7)
47 (defconst X-XF86VidMode-op-DeleteModeLine 8)
48 (defconst X-XF86VidMode-op-ValidateModeLine 9)
49 (defconst X-XF86VidMode-op-SwitchToMode 10)
50 (defconst X-XF86VidMode-op-GetViewPort  11)
51 (defconst X-XF86VidMode-op-SetViewPort  12)
52
53 ;; new for version 2.x of this extension
54 (defconst X-XF86VidMode-op-GetDotClocks 13)
55 (defconst X-XF86VidMode-op-SetClientVersion 14)
56 (defconst X-XF86VidMode-op-SetGamma 15 "Opcode to set new gamma.")
57 (defconst X-XF86VidMode-op-GetGamma 16 "Opcode to fetch current gamma.")
58 (defconst X-XF86VidMode-op-GetGammaRamp 17)
59 (defconst X-XF86VidMode-op-SetGammaRamp 18)
60 (defconst X-XF86VidMode-op-GetGammaRampSize 19)
61
62 \f
63 ;;; Functions
64 (defun X-XF86VidModeQueryVersion (xdpy)
65   "On display XDPY query for version of XF86VidMode extension."
66   (X-Dpy-p xdpy 'X-XF86VidModeQueryVersion)
67
68   (let* ((xin-ext (X-Dpy-get-extension xdpy "XFree86-VidModeExtension" 'X-XF86VidModeQueryVersion))
69          (ListOfFields
70           (list (vector 1 (nth 4 xin-ext)) ; opcode
71                 [1 X-XF86VidMode-op-QueryVersion]
72                 [2 1]))                 ; length
73          (msg (X-Create-message ListOfFields))
74          (ReceiveFields
75           (list [1 success]             ;success field
76                 nil
77                 (list [1 nil]           ;not used
78                       [2 integerp]      ;sequence number
79                       [4 nil]           ;length
80                       [2 integerp]      ;major version
81                       [2 integerp]      ;minor version
82                       [20 nil]))))      ;pad
83     (X-Dpy-send-read xdpy msg ReceiveFields)))
84
85 (defun X-XF86VidModeGetModeline (xdpy &optional screen-num)
86   "On display XDPY using XF86VidMode extension fetch current modeline."
87   (X-Dpy-p xdpy 'X-XF86VidModeGetModeline)
88
89   (let* ((xin-ext (X-Dpy-get-extension xdpy "XFree86-VidModeExtension" 'X-XF86VidModeGetModeline))
90          (ListOfFields
91           (list (vector 1 (nth 4 xin-ext)) ; opcode
92                 [1 X-XF86VidMode-op-GetModeLine]
93                 [2 2]                   ; length
94                 [2 (or screen-num 0)]   ; screen
95                 [2 nil]))               ; pad
96          (msg (X-Create-message ListOfFields))
97          (ReceiveFields
98           (list [1 success]             ;success field
99                 nil
100                 (list [1 nil]           ;not used
101                       [2 integerp]      ;sequence number
102                       [4 nil]           ;length
103                       [4 integerp]      ;dotclock
104                       [2 integerp]      ;hdisplay
105                       [2 integerp]      ;hsyncstart
106                       [2 integerp]      ;hsyncend
107                       [2 integerp]      ;htotal
108                       [2 integerp]      ;hskew
109                       [2 integerp]      ;vdisplay
110                       [2 integerp]      ;vsyncstart
111                       [2 integerp]      ;vsyncend
112                       [2 integerp]      ;vtotal
113                       [2 nil]           ; pad
114                       [4 integerp]))))  ; flags
115     (X-Dpy-send-read xdpy msg ReceiveFields)))
116
117
118 (defun X-XF86VidModeGetGamma (xdpy &optional screen-num)
119   "On display XDPY using XF86VidMode extension fetch current gamma."
120   (X-Dpy-p xdpy 'X-XF86VidModeGetGamma)
121
122   (let* ((xin-ext (X-Dpy-get-extension xdpy "XFree86-VidModeExtension" 'X-XF86VidModeGetGamma))
123          (ListOfFields
124           (list (vector 1 (nth 4 xin-ext)) ; opcode
125                 [1 X-XF86VidMode-op-GetGamma]
126                 [2 8]                   ; length
127                 [2 (or screen-num 0)]   ; screen
128                 [2 nil]                 ; pad
129                 [24 nil]))              ;pad
130          (msg (X-Create-message ListOfFields))
131          (ReceiveFields
132           (list [1 success]             ;success field
133                 nil
134                 (list [1 nil]           ;not used
135                       [2 integerp]      ;sequence number
136                       [4 nil]           ;length
137                       [4 integerp]      ;red gamma
138                       [4 integerp]      ;green gamma
139                       [4 integerp]      ;blue gamma
140                       [12 nil]))))      ;pad
141     (X-Dpy-send-read xdpy msg ReceiveFields)))
142
143 (defun X-XF86VidModeSetGamma (xdpy r g b &optional screen-num)
144   "On display XDPY using XF86VidMode extension fetch current gamma."
145   (X-Dpy-p xdpy 'X-XF86VidModeSetGamma)
146
147   (let* ((xin-ext (X-Dpy-get-extension xdpy "XFree86-VidModeExtension" 'X-XF86VidModeSetGamma))
148          (ListOfFields
149           (list (vector 1 (nth 4 xin-ext)) ; opcode
150                 [1 X-XF86VidMode-op-SetGamma]
151                 [2 8]                   ; length
152                 [2 (or screen-num 0)]   ; screen
153                 [2 nil]                 ; pad
154                 [4 (* 10000 r)]         ; red gamma
155                 [4 (* 10000 g)]         ; green gamma
156                 [4 (* 10000 b)]         ; blue gamma
157                 [12 nil]))              ;pad
158          (msg (X-Create-message ListOfFields)))
159     (X-Dpy-send xdpy msg)))
160
161 ;; TODO: write other functions
162   
163
164 \f
165 (provide 'xlib-vidmode)
166
167 ;;; xlib-vidmode.el ends here