This source file includes following definitions.
- Activate
- IsXvfbSession
- Create
#include "remoting/host/curtain_mode.h"
#include <X11/extensions/XInput.h>
#include "base/callback.h"
#include "base/single_thread_task_runner.h"
#include "remoting/base/logging.h"
#include "remoting/host/client_session_control.h"
namespace remoting {
class CurtainModeLinux : public CurtainMode {
public:
CurtainModeLinux();
virtual bool Activate() OVERRIDE;
private:
bool IsXvfbSession();
DISALLOW_COPY_AND_ASSIGN(CurtainModeLinux);
};
CurtainModeLinux::CurtainModeLinux() {
}
bool CurtainModeLinux::Activate() {
bool activated = IsXvfbSession();
if (!activated) {
LOG(ERROR) << "Curtain-mode is not supported when running on non-Xvfb "
"X server";
}
return activated;
}
bool CurtainModeLinux::IsXvfbSession() {
Display* display = XOpenDisplay(NULL);
int opcode, event, error;
if (!XQueryExtension(display, "XInputExtension", &opcode, &event, &error)) {
LOG(ERROR) << "X Input extension not available: " << error;
XCloseDisplay(display);
return false;
}
int num_devices;
XDeviceInfo* devices;
bool found_xvfb_mouse = false;
bool found_xvfb_keyboard = false;
bool found_other_devices = false;
devices = XListInputDevices(display, &num_devices);
for (int i = 0; i < num_devices; i++) {
XDeviceInfo* device_info = &devices[i];
if (device_info->use == IsXExtensionPointer) {
if (strcmp(device_info->name, "Xvfb mouse") == 0) {
found_xvfb_mouse = true;
} else if (strcmp(device_info->name, "Virtual core XTEST pointer") != 0) {
found_other_devices = true;
HOST_LOG << "Non Xvfb mouse found: " << device_info->name;
}
} else if (device_info->use == IsXExtensionKeyboard) {
if (strcmp(device_info->name, "Xvfb keyboard") == 0) {
found_xvfb_keyboard = true;
} else if (strcmp(device_info->name,
"Virtual core XTEST keyboard") != 0) {
found_other_devices = true;
HOST_LOG << "Non Xvfb keyboard found: " << device_info->name;
}
} else if (device_info->use == IsXPointer) {
if (strcmp(device_info->name, "Virtual core pointer") != 0) {
found_other_devices = true;
HOST_LOG << "Non Xvfb mouse found: " << device_info->name;
}
} else if (device_info->use == IsXKeyboard) {
if (strcmp(device_info->name, "Virtual core keyboard") != 0) {
found_other_devices = true;
HOST_LOG << "Non Xvfb keyboard found: " << device_info->name;
}
} else {
found_other_devices = true;
HOST_LOG << "Non Xvfb device found: " << device_info->name;
}
}
XFreeDeviceList(devices);
XCloseDisplay(display);
return found_xvfb_mouse && found_xvfb_keyboard && !found_other_devices;
}
scoped_ptr<CurtainMode> CurtainMode::Create(
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
base::WeakPtr<ClientSessionControl> client_session_control) {
return scoped_ptr<CurtainMode>(new CurtainModeLinux());
}
}