VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/xclient/displaychange-x11.cpp@ 7082

Last change on this file since 7082 was 6970, checked in by vboxsync, 17 years ago

Additions/X11: first attempt at dynamic guest resizing

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1/** @file
2 *
3 * Guest client: display auto-resize.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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
18#include <VBox/VBoxGuest.h>
19#include <iprt/assert.h>
20
21/** @todo this should probably be replaced by something IPRT */
22/* For system() and WEXITSTATUS() */
23#include <stdlib.h>
24#include <sys/types.h>
25#include <sys/wait.h>
26#include <errno.h>
27
28#include "displaychange.h"
29
30int VBoxGuestDisplayChangeThreadX11::init(void)
31{
32 int rc, rcSystem, rcErrno;
33
34 rcSystem = system("VBoxRandR --test");
35 if (-1 == rcSystem)
36 {
37 rcErrno = errno;
38 rc = RTErrConvertFromErrno(rcErrno);
39 }
40 if (RT_SUCCESS(rc))
41 {
42 if (0 != WEXITSTATUS(rcSystem))
43 rc = VERR_NOT_SUPPORTED;
44 }
45 if (RT_SUCCESS(rc))
46 rc = VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 0);
47 if (RT_SUCCESS(rc))
48 mInit = true;
49 return rc;
50}
51
52void VBoxGuestDisplayChangeThreadX11::uninit(void)
53{
54 VbglR3CtlFilterMask(0, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
55 mInit = false;
56}
57
58/**
59 * Display change request monitor thread function
60 */
61int VBoxGuestDisplayChangeThreadX11::threadFunction(VBoxGuestThread *pThread)
62{
63 mThread = pThread;
64 while (!mThread->isStopping())
65 {
66 uint32_t cx, cy, cBits, iDisplay;
67 int rc = VbglR3DisplayChangeWaitEvent(&cx, &cy, &cBits, &iDisplay);
68 /* If we are not stopping, sleep for a bit to avoid using up too
69 much CPU while retrying. */
70 if (RT_FAILURE(rc) && !mThread->isStopping())
71 mThread->yield();
72 else
73 system("VBoxRandR");
74 }
75 return VINF_SUCCESS;
76}
77
78/**
79 * Send a signal to the thread function that it should exit
80 */
81void VBoxGuestDisplayChangeThreadX11::stop(void)
82{
83 /**
84 * @todo is this reasonable? If the thread is in the event loop then the cancelEvent()
85 * will cause it to exit. If it enters or exits the event loop it will also
86 * notice that we wish it to exit. And if it is somewhere in-between, the
87 * yield() should give it time to get to one of places mentioned above.
88 */
89 for (int i = 0; (i < 5) && mThread->isRunning(); ++i)
90 {
91 VbglR3InterruptEventWaits();;
92 mThread->yield();
93 }
94}
95
96int VBoxGuestDisplayChangeMonitor::init(void)
97{
98 int rc = VINF_SUCCESS;
99
100 if (mInit)
101 return VINF_SUCCESS;
102 rc = mThreadFunction.init();
103 if (RT_FAILURE(rc))
104 Log(("VBoxClient: failed to initialise the display change thread, rc=%Rrc (VBoxGuestDisplayChangeMonitor::init)\n", rc));
105 if (RT_SUCCESS(rc))
106 {
107 rc = mThread.start();
108 if (RT_FAILURE(rc))
109 Log(("VBoxClient: failed to start the display change thread, rc=%Rrc (VBoxGuestDisplayChangeMonitor::init)\n", rc));
110 }
111 if (RT_SUCCESS(rc))
112 mInit = true;
113 return rc;
114}
115
116void VBoxGuestDisplayChangeMonitor::uninit(unsigned cMillies /* = RT_INDEFINITE_WAIT */)
117{
118 if (mInit)
119 {
120 if (mThread.stop(cMillies, 0))
121 mThreadFunction.uninit();
122 }
123}
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