~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to ica/x11/x11vnc/xrandr.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080617134654-cl0gi4u524cv1ici
Tags: 1:1.0.9~rc3-1
* Package new upstream version
  - upstream ported the code to qt4.4 (Closes: #481974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -- xrandr.c -- */
 
2
 
 
3
#include "x11vnc.h"
 
4
#include "cleanup.h"
 
5
#include "connections.h"
 
6
#include "remote.h"
 
7
#include "screen.h"
 
8
#include "win_utils.h"
 
9
 
 
10
time_t last_subwin_trap = 0;
 
11
int subwin_trap_count = 0;
 
12
XErrorHandler old_getimage_handler;
 
13
 
 
14
int xrandr_present = 0;
 
15
int xrandr_width  = -1;
 
16
int xrandr_height = -1;
 
17
int xrandr_rotation = -1;
 
18
Time xrandr_timestamp = 0;
 
19
Time xrandr_cfg_time = 0;
 
20
 
 
21
void initialize_xrandr(void);
 
22
int check_xrandr_event(char *msg);
 
23
int known_xrandr_mode(char *s);
 
24
 
 
25
static int handle_subwin_resize(char *msg);
 
26
static void handle_xrandr_change(int new_x, int new_y);
 
27
 
 
28
 
 
29
void initialize_xrandr(void) {
 
30
        if (xrandr_present && dpy) {
 
31
#if LIBVNCSERVER_HAVE_LIBXRANDR
 
32
                Rotation rot;
 
33
 
 
34
                X_LOCK;
 
35
                xrandr_width  = XDisplayWidth(dpy, scr);
 
36
                xrandr_height = XDisplayHeight(dpy, scr);
 
37
                XRRRotations(dpy, scr, &rot);
 
38
                xrandr_rotation = (int) rot;
 
39
                if (xrandr || xrandr_maybe) {
 
40
                        XRRSelectInput(dpy, rootwin, RRScreenChangeNotifyMask);
 
41
                } else {
 
42
                        XRRSelectInput(dpy, rootwin, 0);
 
43
                }
 
44
                X_UNLOCK;
 
45
#endif
 
46
        } else if (xrandr) {
 
47
                rfbLog("-xrandr mode specified, but no RANDR support on\n");
 
48
                rfbLog(" display or in client library. Disabling -xrandr "
 
49
                    "mode.\n");
 
50
                xrandr = 0;
 
51
        }
 
52
}
 
53
 
 
54
static int handle_subwin_resize(char *msg) {
 
55
        int new_x, new_y;
 
56
        int i, check = 10, ms = 250;    /* 2.5 secs total... */
 
57
 
 
58
        if (msg) {}     /* unused vars warning: */
 
59
        if (! subwin) {
 
60
                return 0;       /* hmmm... */
 
61
        }
 
62
        if (! valid_window(subwin, NULL, 0)) {
 
63
                rfbLogEnable(1);
 
64
                rfbLog("subwin 0x%lx went away!\n", subwin);
 
65
                X_UNLOCK;
 
66
                clean_up_exit(1);
 
67
        }
 
68
        if (! get_window_size(subwin, &new_x, &new_y)) {
 
69
                rfbLogEnable(1);
 
70
                rfbLog("could not get size of subwin 0x%lx\n", subwin);
 
71
                X_UNLOCK;
 
72
                clean_up_exit(1);
 
73
        }
 
74
        if (wdpy_x == new_x && wdpy_y == new_y) {
 
75
                /* no change */
 
76
                return 0;
 
77
        }
 
78
 
 
79
        /* window may still be changing (e.g. drag resize) */
 
80
        for (i=0; i < check; i++) {
 
81
                int newer_x, newer_y;
 
82
                usleep(ms * 1000);
 
83
 
 
84
                if (! get_window_size(subwin, &newer_x, &newer_y)) {
 
85
                        rfbLogEnable(1);
 
86
                        rfbLog("could not get size of subwin 0x%lx\n", subwin);
 
87
                        clean_up_exit(1);
 
88
                }
 
89
                if (new_x == newer_x && new_y == newer_y) {
 
90
                        /* go for it... */
 
91
                        break;
 
92
                } else {
 
93
                        rfbLog("subwin 0x%lx still changing size...\n", subwin);
 
94
                        new_x = newer_x;
 
95
                        new_y = newer_y;
 
96
                }
 
97
        }
 
98
 
 
99
        rfbLog("subwin 0x%lx new size: x: %d -> %d, y: %d -> %d\n",
 
100
            subwin, wdpy_x, new_x, wdpy_y, new_y);
 
101
        rfbLog("calling handle_xrandr_change() for resizing\n");
 
102
 
 
103
        X_UNLOCK;
 
104
        handle_xrandr_change(new_x, new_y);
 
105
        return 1;
 
106
}
 
107
 
 
108
static void handle_xrandr_change(int new_x, int new_y) {
 
109
        rfbClientIteratorPtr iter;
 
110
        rfbClientPtr cl;
 
111
 
 
112
        RAWFB_RET_VOID
 
113
 
 
114
        /* sanity check xrandr_mode */
 
115
        if (! xrandr_mode) {
 
116
                xrandr_mode = strdup("default");
 
117
        } else if (! known_xrandr_mode(xrandr_mode)) {
 
118
                free(xrandr_mode);
 
119
                xrandr_mode = strdup("default");
 
120
        }
 
121
        rfbLog("xrandr_mode: %s\n", xrandr_mode);
 
122
        if (!strcmp(xrandr_mode, "exit")) {
 
123
                close_all_clients();
 
124
                rfbLog("  shutting down due to XRANDR event.\n");
 
125
                clean_up_exit(0);
 
126
        }
 
127
        if (!strcmp(xrandr_mode, "newfbsize") && screen) {
 
128
                iter = rfbGetClientIterator(screen);
 
129
                while( (cl = rfbClientIteratorNext(iter)) ) {
 
130
                        if (cl->useNewFBSize) {
 
131
                                continue;
 
132
                        }
 
133
                        rfbLog("  closing client %s (no useNewFBSize"
 
134
                            " support).\n", cl->host);
 
135
                        rfbCloseClient(cl);
 
136
                        rfbClientConnectionGone(cl);
 
137
                }
 
138
                rfbReleaseClientIterator(iter);
 
139
        }
 
140
        
 
141
        /* default, resize, and newfbsize create a new fb: */
 
142
        rfbLog("check_xrandr_event: trying to create new framebuffer...\n");
 
143
        if (new_x < wdpy_x || new_y < wdpy_y) {
 
144
                check_black_fb();
 
145
        }
 
146
        do_new_fb(1);
 
147
        rfbLog("check_xrandr_event: fb       WxH: %dx%d\n", wdpy_x, wdpy_y);
 
148
}
 
149
 
 
150
int check_xrandr_event(char *msg) {
 
151
        XEvent xev;
 
152
 
 
153
        RAWFB_RET(0)
 
154
 
 
155
        if (subwin) {
 
156
                return handle_subwin_resize(msg);
 
157
        }
 
158
#if LIBVNCSERVER_HAVE_LIBXRANDR
 
159
        if (! xrandr_present) {
 
160
                return 0;
 
161
        }
 
162
        if (! xrandr && ! xrandr_maybe) {
 
163
                return 0;
 
164
        }
 
165
        if (xrandr_base_event_type && XCheckTypedEvent(dpy,
 
166
            xrandr_base_event_type + RRScreenChangeNotify, &xev)) {
 
167
                int do_change, qout = 0;
 
168
                static int first = 1;
 
169
                XRRScreenChangeNotifyEvent *rev;
 
170
 
 
171
                rev = (XRRScreenChangeNotifyEvent *) &xev;
 
172
 
 
173
                if (first && ! xrandr) {
 
174
                        fprintf(stderr, "\n");
 
175
                        qout = 1;
 
176
                }
 
177
                first = 0;
 
178
                        
 
179
                rfbLog("check_xrandr_event():\n");
 
180
                rfbLog("Detected XRANDR event at location '%s':\n", msg);
 
181
 
 
182
                if (qout) {
 
183
                        ;
 
184
                } else {
 
185
                        rfbLog("  serial:          %d\n", (int) rev->serial);
 
186
                        rfbLog("  timestamp:       %d\n", (int) rev->timestamp);
 
187
                        rfbLog("  cfg_timestamp:   %d\n", (int) rev->config_timestamp);
 
188
                        rfbLog("  size_id:         %d\n", (int) rev->size_index);
 
189
                        rfbLog("  sub_pixel:       %d\n", (int) rev->subpixel_order);
 
190
                        rfbLog("  rotation:        %d\n", (int) rev->rotation);
 
191
                        rfbLog("  width:           %d\n", (int) rev->width);
 
192
                        rfbLog("  height:          %d\n", (int) rev->height);
 
193
                        rfbLog("  mwidth:          %d mm\n", (int) rev->mwidth);
 
194
                        rfbLog("  mheight:         %d mm\n", (int) rev->mheight);
 
195
                        rfbLog("\n");
 
196
                        rfbLog("check_xrandr_event: previous WxH: %dx%d\n",
 
197
                            wdpy_x, wdpy_y);
 
198
                }
 
199
 
 
200
                if (wdpy_x == rev->width && wdpy_y == rev->height &&
 
201
                    xrandr_rotation == (int) rev->rotation) {
 
202
                    rfbLog("check_xrandr_event: no change detected.\n");
 
203
                        do_change = 0;
 
204
                } else {
 
205
                        do_change = 1;
 
206
                        if (! xrandr) {
 
207
                                rfbLog("check_xrandr_event: Resize; "
 
208
                                    "enabling full XRANDR trapping.\n");
 
209
                                xrandr = 1;
 
210
                        }
 
211
                }
 
212
 
 
213
                xrandr_width  = rev->width;
 
214
                xrandr_height = rev->height;
 
215
                xrandr_timestamp = rev->timestamp;
 
216
                xrandr_cfg_time  = rev->config_timestamp;
 
217
                xrandr_rotation = (int) rev->rotation;
 
218
 
 
219
                if (! qout) rfbLog("check_xrandr_event: updating config...\n");
 
220
                XRRUpdateConfiguration(&xev);
 
221
 
 
222
                if (do_change) {
 
223
                        X_UNLOCK;
 
224
                        handle_xrandr_change(rev->width, rev->height);
 
225
                }
 
226
                if (qout) {
 
227
                        return do_change;
 
228
                }
 
229
                rfbLog("check_xrandr_event: current  WxH: %dx%d\n",
 
230
                    XDisplayWidth(dpy, scr), XDisplayHeight(dpy, scr));
 
231
                rfbLog("check_xrandr_event(): returning control to"
 
232
                    " caller...\n");
 
233
                return do_change;
 
234
        }
 
235
#else
 
236
        xev.type = 0;
 
237
#endif
 
238
        return 0;
 
239
}
 
240
 
 
241
int known_xrandr_mode(char *s) {
 
242
/*
 
243
 * default:     
 
244
 * resize:      the default
 
245
 * exit:        shutdown clients and exit.
 
246
 * newfbsize:   shutdown clients that do not support NewFBSize encoding.
 
247
 */
 
248
        if (strcmp(s, "default") && strcmp(s, "resize") && 
 
249
            strcmp(s, "exit") && strcmp(s, "newfbsize")) {
 
250
                return 0;
 
251
        } else {
 
252
                return 1;
 
253
        }
 
254
}
 
255
 
 
256