VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/VBoxClient/autoresize.cpp@ 18938

Last change on this file since 18938 was 18938, checked in by vboxsync, 16 years ago

Additions/x11/VBoxClient: detect X server termination and remove two unused files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/** @file
2 *
3 * Guest client: display auto-resize.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/** @todo this should probably be replaced by something IPRT */
23/* For system() and WEXITSTATUS() */
24#include <stdlib.h>
25#include <sys/types.h>
26#include <sys/wait.h>
27#include <errno.h>
28
29#include <X11/Xlib.h>
30
31#include <iprt/assert.h>
32#include <iprt/thread.h>
33#include <VBox/log.h>
34#include <VBox/VBoxGuest.h>
35
36#include "VBoxClient.h"
37
38static int initAutoResize()
39{
40 int rc = VINF_SUCCESS, rcSystem, rcErrno;
41
42 LogFlowFunc(("\n"));
43 rcSystem = system("VBoxRandR --test");
44 if (-1 == rcSystem)
45 {
46 rcErrno = errno;
47 rc = RTErrConvertFromErrno(rcErrno);
48 }
49 if (RT_SUCCESS(rc))
50 {
51 if (0 != WEXITSTATUS(rcSystem))
52 rc = VERR_NOT_SUPPORTED;
53 }
54 if (RT_SUCCESS(rc))
55 rc = VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 0);
56 LogFlowFunc(("returning %Rrc\n", rc));
57 return rc;
58}
59
60void cleanupAutoResize(void)
61{
62 LogFlowFunc(("\n"));
63 VbglR3CtlFilterMask(0, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
64 LogFlowFunc(("returning\n"));
65}
66
67/**
68 * Display change request monitor thread function.
69 * Before entering the loop, we re-read the last request
70 * received, and if the first one received inside the
71 * loop is identical we ignore it, because it is probably
72 * stale.
73 */
74int runAutoResize()
75{
76 LogFlowFunc(("\n"));
77 /* Keep an open display so that we terminate if X11 does. */
78 Display *pDisplay = XOpenDisplay(NULL);
79 uint32_t cx0 = 0, cy0 = 0, cBits0 = 0, iDisplay0 = 0;
80 int rc = VbglR3GetLastDisplayChangeRequest(&cx0, &cy0, &cBits0, &iDisplay0);
81 while (true)
82 {
83 uint32_t cx = 0, cy = 0, cBits = 0, iDisplay = 0;
84 rc = VbglR3DisplayChangeWaitEvent(&cx, &cy, &cBits, &iDisplay);
85 /* Make sure we are still connected to X. If the X server has
86 * terminated then we should get a resize event above. */
87 XPending(pDisplay);
88 /* Ignore the request if it is stale */
89 if ((cx != cx0) || (cy != cy0))
90 {
91 /* If we are not stopping, sleep for a bit to avoid using up too
92 much CPU while retrying. */
93 if (RT_FAILURE(rc))
94 RTThreadYield();
95 else
96 system("VBoxRandR");
97 }
98 /* We do not want to ignore any further requests. */
99 cx0 = 0;
100 cy0 = 0;
101 }
102 XCloseDisplay(pDisplay);
103 LogFlowFunc(("returning VINF_SUCCESS\n"));
104 return VINF_SUCCESS;
105}
106
107class AutoResizeService : public VBoxClient::Service
108{
109public:
110 virtual const char *getPidFilePath()
111 {
112 return ".vboxclient-autoresize.pid";
113 }
114 virtual int run()
115 {
116 int rc = initAutoResize();
117 if (RT_SUCCESS(rc))
118 rc = runAutoResize();
119 return rc;
120 }
121 virtual void cleanup()
122 {
123 cleanupAutoResize();
124 }
125};
126
127VBoxClient::Service *VBoxClient::GetAutoResizeService()
128{
129 return new AutoResizeService;
130}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette