Hash :
fb28d3c5
Author :
Date :
2015-05-21T18:02:02
X11Window: handling of ConfigureNotify, work when reparented BUG=angleproject:892 Change-Id: Ib201a5fbf4fca39c90464ed76434dac5e5ded381 Reviewed-on: https://chromium-review.googlesource.com/272683 Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Corentin Wallez <cwallez@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "OSWindow.h"
#include <iostream>
#include "common/debug.h"
#ifndef DEBUG_EVENTS
#define DEBUG_EVENTS 0
#endif
#if DEBUG_EVENTS
static const char *MouseButtonName(MouseButton button)
{
switch (button)
{
case MOUSEBUTTON_UNKNOWN:
return "Unknown";
case MOUSEBUTTON_LEFT:
return "Left";
case MOUSEBUTTON_RIGHT:
return "Right";
case MOUSEBUTTON_MIDDLE:
return "Middle";
case MOUSEBUTTON_BUTTON4:
return "Button4";
case MOUSEBUTTON_BUTTON5:
return "Button5";
default:
UNREACHABLE();
return nullptr;
}
}
static void PrintEvent(const Event& event)
{
switch (event.Type)
{
case Event::EVENT_CLOSED:
std::cout << "Event: Window Closed" << std::endl;
break;
case Event::EVENT_MOVED:
std::cout << "Event: Window Moved (" << event.Move.X
<< ", " << event.Move.Y << ")" << std::endl;
break;
case Event::EVENT_RESIZED:
std::cout << "Event: Window Resized (" << event.Size.Width
<< ", " << event.Size.Height << ")" << std::endl;
break;
case Event::EVENT_LOST_FOCUS:
std::cout << "Event: Window Lost Focus" << std::endl;
break;
case Event::EVENT_GAINED_FOCUS:
std::cout << "Event: Window Gained Focus" << std::endl;
break;
case Event::EVENT_TEXT_ENTERED:
// TODO(cwallez) show the character
std::cout << "Event: Text Entered" << std::endl;
break;
case Event::EVENT_KEY_PRESSED:
// TODO(cwallez) show the key
std::cout << "Event: Key Pressed" << std::endl;
break;
case Event::EVENT_KEY_RELEASED:
// TODO(cwallez) show the key
std::cout << "Event: Key Released" << std::endl;
break;
case Event::EVENT_MOUSE_WHEEL_MOVED:
std::cout << "Event: Mouse Wheel (" << event.MouseWheel.Delta << ")" << std::endl;
break;
case Event::EVENT_MOUSE_BUTTON_PRESSED:
std::cout << "Event: Mouse Button Pressed " << MouseButtonName(event.MouseButton.Button) <<
" at (" << event.MouseButton.X << ", " << event.MouseButton.Y << ")" << std::endl;
break;
case Event::EVENT_MOUSE_BUTTON_RELEASED:
std::cout << "Event: Mouse Button Released " << MouseButtonName(event.MouseButton.Button) <<
" at (" << event.MouseButton.X << ", " << event.MouseButton.Y << ")" << std::endl;
break;
case Event::EVENT_MOUSE_MOVED:
std::cout << "Event: Mouse Moved (" << event.MouseMove.X
<< ", " << event.MouseMove.Y << ")" << std::endl;
break;
case Event::EVENT_MOUSE_ENTERED:
std::cout << "Event: Mouse Entered Window" << std::endl;
break;
case Event::EVENT_MOUSE_LEFT:
std::cout << "Event: Mouse Left Window" << std::endl;
break;
case Event::EVENT_TEST:
std::cout << "Event: Test" << std::endl;
break;
default:
UNREACHABLE();
break;
}
}
#endif
OSWindow::OSWindow()
: mX(0),
mY(0),
mWidth(0),
mHeight(0)
{
}
OSWindow::~OSWindow()
{}
int OSWindow::getX() const
{
return mX;
}
int OSWindow::getY() const
{
return mY;
}
int OSWindow::getWidth() const
{
return mWidth;
}
int OSWindow::getHeight() const
{
return mHeight;
}
bool OSWindow::popEvent(Event *event)
{
if (mEvents.size() > 0 && event)
{
*event = mEvents.front();
mEvents.pop_front();
return true;
}
else
{
return false;
}
}
void OSWindow::pushEvent(Event event)
{
switch (event.Type)
{
case Event::EVENT_MOVED:
mX = event.Move.X;
mY = event.Move.Y;
break;
case Event::EVENT_RESIZED:
mWidth = event.Size.Width;
mHeight = event.Size.Height;
break;
default:
break;
}
mEvents.push_back(event);
#if DEBUG_EVENTS
PrintEvent(event);
#endif
}
bool OSWindow::didTestEventFire()
{
Event topEvent;
while (popEvent(&topEvent))
{
if (topEvent.Type == Event::EVENT_TEST)
{
return true;
}
}
return false;
}