1 /*****
2  *       Xnee's Not an Event Emulator
3  *
4  * Xnee enables recording and replaying of X protocol data
5  *
6  *    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Henrik Sandklef
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 3
11  * of the License, or any later version.
12  *
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Boston,
22  * MA  02110-1301, USA.
23  ****/
24 
25 /* This file contains function handling different resolution
26    during reaply than when recording ... */
27 
28 #include "libxnee/xnee.h"
29 #include "libxnee/xnee_setget.h"
30 #include "libxnee/xnee_record.h"
31 #include "libxnee/xnee_replay.h"
32 #include "libxnee/print.h"
33 #include "libxnee/xnee_resolution.h"
34 
35 int
xnee_set_default_rep_resolution(xnee_data * xd)36 xnee_set_default_rep_resolution (xnee_data *xd)
37 {
38   if (xd->data != NULL)
39     {
40       xd->res_info.replay.x_res = DisplayWidth  (xd->data, 0);
41       xd->res_info.replay.y_res = DisplayHeight (xd->data, 0);
42       return XNEE_OK;
43     }
44   return -1 ;
45 }
46 
47 int
xnee_set_default_rec_resolution(xnee_data * xd)48 xnee_set_default_rec_resolution (xnee_data *xd)
49 {
50   if ( (xd!=NULL) &&
51        (xd->data != NULL) )
52     {
53       xd->res_info.record.x_res = DisplayWidth  (xd->data, 0);
54       xd->res_info.record.y_res = DisplayHeight (xd->data, 0);
55       return XNEE_OK;
56     }
57   return -1 ;
58 }
59 
60 
61 int
xnee_no_rep_resolution(xnee_data * xd)62 xnee_no_rep_resolution (xnee_data *xd)
63 {
64   return ( (xd->res_info.replay.x_res != 1) &&
65 	   ( xd->res_info.replay.y_res != 1));
66 }
67 
68 
69 
70 int
xnee_str_to_res(char * res_str,xnee_res * xr)71 xnee_str_to_res(char *res_str, xnee_res *xr)
72 {
73   int ret;
74 
75   if (res_str == NULL)
76     {
77       return XNEE_BAD_RESOLUTION;
78     }
79 
80   if ( ! (  ( xr->x_res == 1 ) && ( xr->y_res == 1 )))
81     {
82       return XNEE_OK;
83     }
84 
85   ret = sscanf(res_str, "%dx%d",
86 	       &xr->x_res,
87 	       &xr->y_res);
88 
89   if ( ret == 2 )
90     {
91       return XNEE_OK;
92     }
93   else if (xnee_check ("VGA", res_str, res_str))
94     {
95       xr->x_res = 800 ;
96       xr->y_res = 640 ;
97       return XNEE_OK;
98     }
99   else if (xnee_check ("SVGA", res_str, res_str))
100     {
101       xr->x_res = 1024 ;
102       xr->y_res = 768 ;
103       return XNEE_OK;
104     }
105   else if (xnee_check ("XGA", res_str, res_str))
106     {
107       xr->x_res = 1280 ;
108       xr->y_res = 1024 ;
109       return XNEE_OK;
110     }
111   else if (xnee_check ("UXGA", res_str, res_str))
112     {
113       xr->x_res = 1600 ;
114       xr->y_res = 1440 ;
115       return XNEE_OK;
116     }
117   else
118     {
119       ;
120     }
121   return XNEE_BAD_RESOLUTION;
122 }
123 
124 
125 int
xnee_res_cmp(xnee_res * xr1,xnee_res * xr2)126 xnee_res_cmp(xnee_res *xr1, xnee_res *xr2)
127 {
128   int ret;
129   ret =  ( ( xr1->x_res == xr2->x_res)
130 	   &&
131 	   ( xr1->y_res == xr2->y_res) );
132   /*
133      1   means same
134      0   means diff
135   */
136   return ret;
137 }
138 
139 
140 int
xnee_resolution_differs(xnee_data * xd)141 xnee_resolution_differs (xnee_data *xd)
142 {
143   if (xnee_res_cmp(&xd->res_info.record,&xd->res_info.replay)==0)
144     {
145       /* diff */
146       return 1;
147     }
148   else
149     {
150       /* no diff */
151       return 0;
152     }
153 }
154 
155 
156 int
xnee_resolution_newx(xnee_data * xd,int xval)157 xnee_resolution_newx (xnee_data *xd, int xval)
158 {
159   static int diff = XNEE_RESOLUTION_UNSET ;
160 
161   if (diff==XNEE_RESOLUTION_UNSET)
162     {
163       if (xnee_is_resolution_used(xd))
164 	{
165 	  if (xnee_resolution_differs(xd))
166 	    {
167 	      diff = XNEE_RESOLUTION_USED;
168 	    }
169 	  else
170 	    {
171 	      diff = XNEE_RESOLUTION_UNUSED;
172 	    }
173 	}
174       else
175 	{
176 	  diff = XNEE_RESOLUTION_UNUSED;
177 	}
178     }
179   if (diff==XNEE_RESOLUTION_USED)
180     {
181       return ( ( xval * xnee_get_rep_resolution_x (xd) )
182 	       / xnee_get_rec_resolution_x (xd));
183     }
184 
185   return xval;
186 }
187 
188 int
xnee_resolution_newy(xnee_data * xd,int yval)189 xnee_resolution_newy (xnee_data *xd, int yval)
190 {
191   static int diff = XNEE_RESOLUTION_UNSET ;
192 
193   if (diff==XNEE_RESOLUTION_UNSET)
194     {
195       if (xnee_is_resolution_used(xd))
196 	{
197 	  if (xnee_resolution_differs(xd))
198 	    {
199 	      diff = XNEE_RESOLUTION_USED;
200 	    }
201 	  else
202 	    {
203 	      diff = XNEE_RESOLUTION_UNUSED;
204 	    }
205 	}
206       else
207 	{
208 	  diff = XNEE_RESOLUTION_UNUSED;
209 	}
210     }
211   if (diff==XNEE_RESOLUTION_USED)
212     {
213       return ( ( yval * xnee_get_rep_resolution_y (xd) )
214 	       / xnee_get_rec_resolution_y (xd));
215     }
216   return yval;
217 }
218 
219 int
xnee_is_resolution_used(xnee_data * xd)220 xnee_is_resolution_used (xnee_data *xd)
221 {
222    if (xd==NULL)
223    {
224       return XNEE_MEMORY_FAULT;
225    }
226   return xd->res_info.is_used==XNEE_RESOLUTION_USED;
227 }
228 
229 int
xnee_set_resolution_used(xnee_data * xd)230 xnee_set_resolution_used (xnee_data *xd)
231 {
232    if (xd==NULL)
233    {
234       return XNEE_MEMORY_FAULT;
235    }
236   xd->res_info.is_used=XNEE_RESOLUTION_USED;
237   return XNEE_OK;
238 }
239 
240 int
xnee_unset_resolution_used(xnee_data * xd)241 xnee_unset_resolution_used (xnee_data *xd)
242 {
243    if (xd==NULL)
244    {
245       return XNEE_MEMORY_FAULT;
246    }
247   xd->res_info.is_used=XNEE_RESOLUTION_UNUSED;
248   return XNEE_OK;
249 }
250 
251 int
xnee_get_resolution_used(xnee_data * xd)252 xnee_get_resolution_used (xnee_data *xd)
253 {
254    if (xd==NULL)
255    {
256       return XNEE_MEMORY_FAULT;
257    }
258   return xd->res_info.is_used;
259 }
260 
261 int
xnee_resolution_init(xnee_data * xd)262 xnee_resolution_init (xnee_data *xd)
263 {
264    xd->res_info.record.x_res=1;
265    xd->res_info.record.y_res=1;
266 
267    xd->res_info.replay.x_res=1;
268    xd->res_info.replay.y_res=1;
269 
270 /*   xnee_set_resolution_used(xd); */
271   return XNEE_OK;
272 }
273 
274 
275 
276