aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-05-07 19:22:26 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-05-07 19:22:26 +0000
commitdbac07f0f02de97b236316497094496069ba1c27 (patch)
treea2bbc7adffbf4fa33db7dd3fe7cfea2387102caa
parentf4710e1379a97a250f7c39d0565ca18251344db4 (diff)
parent65fc3297fbb2a50180948fc81e5d07630859ae64 (diff)
downloadqemu-emu-34-2-dev.tar.gz
Merge changes from topic "emu-34-2-patch1" into emu-34-2-devemu-34-2-dev
* changes: Fix location tab shortcut key. [embedded] Remove Cancel button from snapshot save dialog. Fix snapshot save dialog. Fix "Start a route" button. [embedded] Fix Qt main loop hang on exit. Fix Qt crash on linux-aarch64. Disable window repositioning during screen change. Default-initialize in createSkinEvent based on type. qt6: handle negative coordinates on multi-monitor setups.
-rw-r--r--android/android-ui/modules/aemu-ext-pages/location/src/android/skin/qt/extended-pages/location-page-point.cpp7
-rw-r--r--android/android-ui/modules/aemu-ui-common/include/android/skin/event.h10
-rw-r--r--android/android-ui/modules/aemu-ui-common/src/android/skin/generic-event.cpp79
-rw-r--r--android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/QtLogger.cpp2
-rw-r--r--android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-container.cpp8
-rw-r--r--android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.cpp65
-rw-r--r--android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.h1
-rw-r--r--android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/extended-window.cpp3
-rw-r--r--android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.cpp36
-rw-r--r--android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.h1
-rw-r--r--android/android-ui/modules/aemu-ui-window/src/android/emulator-window.c2
-rw-r--r--android/android-ui/modules/aemu-ui-window/src/android/skin/window.c81
12 files changed, 217 insertions, 78 deletions
diff --git a/android/android-ui/modules/aemu-ext-pages/location/src/android/skin/qt/extended-pages/location-page-point.cpp b/android/android-ui/modules/aemu-ext-pages/location/src/android/skin/qt/extended-pages/location-page-point.cpp
index 14f8879bfa..e1a2e650f8 100644
--- a/android/android-ui/modules/aemu-ext-pages/location/src/android/skin/qt/extended-pages/location-page-point.cpp
+++ b/android/android-ui/modules/aemu-ext-pages/location/src/android/skin/qt/extended-pages/location-page-point.cpp
@@ -317,10 +317,11 @@ void LocationPage::pointWidget_editButtonClicked(CCListItem* listItem) {
if (theAction == startRouteAction) {
// Switch to routes tab with the saved point
auto& pointElement = pointWidgetItem->pointElement();
- emit mMapBridge->startRouteCreatorFromPoint(QString::number(pointElement.latitude, 'g', 12),
- QString::number(pointElement.longitude, 'g', 12),
- pointElement.address);
mUi->locationTabs->setCurrentIndex(1);
+ emit mRoutesMapBridge->startRouteCreatorFromPoint(
+ QString::number(pointElement.latitude, 'g', 12),
+ QString::number(pointElement.longitude, 'g', 12),
+ pointElement.address);
} else if (theAction == editAction && editPoint(pointWidgetItem->pointElement())) {
pointWidgetItem->refresh();
auto& pointElement = pointWidgetItem->pointElement();
diff --git a/android/android-ui/modules/aemu-ui-common/include/android/skin/event.h b/android/android-ui/modules/aemu-ui-common/include/android/skin/event.h
index 6d603ffd00..f7689e3a97 100644
--- a/android/android-ui/modules/aemu-ui-common/include/android/skin/event.h
+++ b/android/android-ui/modules/aemu-ui-common/include/android/skin/event.h
@@ -54,7 +54,6 @@ typedef enum {
kEventTouchBegin,
kEventTouchEnd,
kEventTouchUpdate,
- kEventSetDisplayConfigs,
kEventSetDisplayActiveConfig,
kEventAddDisplay,
kEventRemoveDisplay,
@@ -189,6 +188,14 @@ typedef struct {
uint32_t id;
} SkinEventRemoveDisplay;
+typedef struct {
+ int32_t x;
+ int32_t y;
+ int32_t w;
+ int32_t h;
+ double dpr;
+} SkinEventScreenData;
+
typedef struct SkinEvent {
union {
SkinEventKeyData key;
@@ -208,6 +215,7 @@ typedef struct SkinEvent {
int display_active_config;
SkinEventAddDisplay add_display;
SkinEventRemoveDisplay remove_display;
+ SkinEventScreenData screen;
} u;
SkinEventType type;
} SkinEvent;
diff --git a/android/android-ui/modules/aemu-ui-common/src/android/skin/generic-event.cpp b/android/android-ui/modules/aemu-ui-common/src/android/skin/generic-event.cpp
index 25bad250ab..51e322d089 100644
--- a/android/android-ui/modules/aemu-ui-common/src/android/skin/generic-event.cpp
+++ b/android/android-ui/modules/aemu-ui-common/src/android/skin/generic-event.cpp
@@ -66,7 +66,84 @@ void skin_generic_event_free(SkinGenericEvent* generic_event) {
}
SkinEvent createSkinEvent(SkinEventType t) {
- SkinEvent e{};
+ SkinEvent e;
e.type = t;
+ switch (t) {
+ case kEventKeyDown:
+ case kEventKeyUp:
+ e.u.key = {};
+ break;
+ case kEventGeneric:
+ e.u.generic_event = {};
+ break;
+ case kEventTextInput:
+ e.u.text = {};
+ break;
+ case kEventMouseButtonDown:
+ case kEventMouseButtonUp:
+ case kEventMouseMotion:
+ case kEventMouseStartTracking:
+ case kEventMouseStopTracking:
+ e.u.mouse = {};
+ break;
+ case kEventMouseWheel:
+ e.u.wheel = {};
+ break;
+ case kEventScrollBarChanged:
+ case kEventZoomedWindowResized:
+ e.u.scroll = {};
+ break;
+ case kEventRotaryInput:
+ e.u.rotary_input = {};
+ break;
+ case kEventSetScale:
+ case kEventSetZoom:
+ case kEventWindowMoved:
+ case kEventWindowChanged:
+ e.u.window = {};
+ break;
+ case kEventLayoutRotate:
+ e.u.layout_rotation = {};
+ break;
+ case kEventScreenChanged:
+ e.u.screen = {};
+ break;
+ case kEventSetDisplayRegion:
+ case kEventSetDisplayRegionAndUpdate:
+ e.u.display_region = {};
+ break;
+ case kEventPenPress:
+ case kEventPenRelease:
+ case kEventPenMove:
+ e.u.pen = {};
+ break;
+ case kEventTouchBegin:
+ case kEventTouchEnd:
+ case kEventTouchUpdate:
+ e.u.multi_touch_point = {};
+ break;
+ case kEventSetDisplayActiveConfig:
+ e.u.display_active_config = {};
+ break;
+ case kEventAddDisplay:
+ e.u.add_display = {};
+ break;
+ case kEventRemoveDisplay:
+ e.u.remove_display = {};
+ break;
+ case kEventQuit:
+ case kEventForceRedraw:
+ case kEventToggleTrackball:
+ case kEventSetNoSkin:
+ case kEventRestoreSkin:
+ case kEventSetFoldedSkin:
+ // No additional parameters
+ break;
+ default:
+ // Crash if there's an unhandled SkinEventType, as we want an explicit initialization
+ // for each type.
+ dfatal("Unknown SkinEventType=%u", t);
+ break;
+ }
return e;
}
diff --git a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/QtLogger.cpp b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/QtLogger.cpp
index 2f55055bb5..a05a7e513c 100644
--- a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/QtLogger.cpp
+++ b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/QtLogger.cpp
@@ -39,7 +39,7 @@ void QtLogger::write(const char* fmt, ...) {
mbstowcs(wfmt.data(), fmt, wfmt.size());
va_list ap;
va_start(ap, fmt);
- vswprintf(buf, sizeof(buf) - 1, wfmt.data(), ap);
+ vswprintf(buf, sizeof(buf)/sizeof(wchar_t), wfmt.data(), ap);
va_end(ap);
wcstombs(cbuf, buf, std::size(cbuf));
diff --git a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-container.cpp b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-container.cpp
index d6b669e5ba..1ded7ca5b5 100644
--- a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-container.cpp
+++ b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-container.cpp
@@ -272,6 +272,14 @@ void EmulatorContainer::closeEvent(QCloseEvent* event) {
slot_hideModalOverlay();
slot_hideVirtualSceneInfoDialog();
mEmulatorWindow->closeEvent(event);
+ // In embedded mode, sometimes QCoreApplication::quit() doesn't get called,
+ // which means the Qt main loop never quits. So let's explicitly call quit()
+ // here prevent that situation from occurring.
+ if (getConsoleAgents()
+ ->settings->android_cmdLineOptions()
+ ->qt_hide_window) {
+ qApp->quit();
+ }
}
void EmulatorContainer::focusInEvent(QFocusEvent* event) {
diff --git a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.cpp b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.cpp
index 470a3a4dc0..f7f4d2b6d8 100644
--- a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.cpp
+++ b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.cpp
@@ -343,6 +343,25 @@ void SkinSurfaceBitmap::readImage() {
}
}
+SkinEvent EmulatorQtWindow::createSkinEventScreenChanged() {
+ QRect screen_geo;
+ getScreenDimensions(&screen_geo);
+ double dpr;
+ getDevicePixelRatio(&dpr);
+
+ // On multi-monitor setups, x and y coordinates can have negative values, as the coordinates are
+ // relative to the top-left corner (0, 0) of the primary display.
+ SkinEvent skin_event = createSkinEvent(kEventScreenChanged);
+ skin_event.u.screen.x = screen_geo.x();
+ skin_event.u.screen.y = screen_geo.y();
+ skin_event.u.screen.w = screen_geo.width();
+ skin_event.u.screen.h = screen_geo.height();
+ skin_event.u.screen.dpr = dpr;
+ D("%s: x=%d y=%d w=%d h=%d dpr=%f\n", __func__, skin_event.u.screen.x, skin_event.u.screen.y,
+ skin_event.u.screen.w, skin_event.u.screen.h, skin_event.u.screen.dpr);
+ return skin_event;
+}
+
////////////////////////////////////////////////////////////////////////////////
void EmulatorQtWindow::create() {
@@ -1405,7 +1424,11 @@ void EmulatorQtWindow::maskWindowFrame() {
eventType = kEventScreenChanged;
mHardRefreshCountDown--;
}
- queueSkinEvent(createSkinEvent(eventType));
+ if (eventType == kEventScreenChanged) {
+ queueSkinEvent(createSkinEventScreenChanged());
+ } else {
+ queueSkinEvent(createSkinEvent(eventType));
+ }
}
void EmulatorQtWindow::paintEvent(QPaintEvent*) {
@@ -1414,17 +1437,19 @@ void EmulatorQtWindow::paintEvent(QPaintEvent*) {
painter.fillRect(bg, Qt::black);
if (mBackingSurface) {
+ double dpr = 1.0;
+ slot_getDevicePixelRatio(&dpr);
QRect r(0, 0, mBackingSurface->w, mBackingSurface->h);
if (mBackingBitmapChanged) {
mScaledBackingImage =
QPixmap::fromImage(mBackingSurface->bitmap->get().scaled(
- r.size() * devicePixelRatioF(), Qt::KeepAspectRatio,
+ r.size() * dpr, Qt::KeepAspectRatio,
Qt::SmoothTransformation));
mBackingBitmapChanged = false;
}
if (!mScaledBackingImage.isNull()) {
- if (mScaledBackingImage.devicePixelRatio() != devicePixelRatioF()) {
- mScaledBackingImage.setDevicePixelRatio(devicePixelRatioF());
+ if (mScaledBackingImage.devicePixelRatio() != dpr) {
+ mScaledBackingImage.setDevicePixelRatio(dpr);
}
painter.drawPixmap(r, mScaledBackingImage);
}
@@ -1476,7 +1501,7 @@ void EmulatorQtWindow::setFrameAlways(bool frameAlways) {
}
D("%s: kEventScreenChanged", __FUNCTION__);
- queueSkinEvent(createSkinEvent(kEventScreenChanged));
+ queueSkinEvent(createSkinEventScreenChanged());
}
void EmulatorQtWindow::setIgnoreWheelEvent(bool ignore) {
@@ -1649,7 +1674,7 @@ bool EmulatorQtWindow::event(QEvent* ev) {
#endif
// Trigger a ScreenChanged event so the device
// screen will refresh immediately
- queueSkinEvent(createSkinEvent(kEventScreenChanged));
+ queueSkinEvent(createSkinEventScreenChanged());
#endif // !_WIN32
}
@@ -1744,7 +1769,8 @@ void EmulatorQtWindow::slot_fill(SkinSurface* s,
void EmulatorQtWindow::slot_getDevicePixelRatio(double* out_dpr,
QSemaphore* semaphore) {
QSemaphoreReleaser semReleaser(semaphore);
- *out_dpr = devicePixelRatioF();
+ auto screen = window()->windowHandle() ? window()->windowHandle()->screen() : nullptr;
+ *out_dpr = screen ? screen->devicePixelRatio() : 1.0;
}
void EmulatorQtWindow::slot_getScreenDimensions(QRect* out_rect,
@@ -1759,22 +1785,17 @@ void EmulatorQtWindow::slot_getScreenDimensions(QRect* out_rect,
: nullptr;
if (!newScreen) {
D("Can't get screen geometry. Window is off screen.");
+ return;
}
- QRect rect = newScreen->geometry();
+ // Use availableGeometry() instead of geometry() to get coordinates that are excluding things
+ // like a dock, menu bar, etc.
+ QRect rect = newScreen->availableGeometry();
D("slot_getScreenDimensions: Getting screen geometry (done)");
out_rect->setX(rect.x());
out_rect->setY(rect.y());
- // Always report slightly smaller-than-actual dimensions to prevent odd
- // resizing behavior, which can happen if things like the OSX dock are
- // not taken into account. The difference below is specifically to take
- // into account the OSX dock.
- out_rect->setWidth(rect.width() * .95);
-#ifdef __APPLE__
- out_rect->setHeight(rect.height() * .85);
-#else // _WIN32 || __linux__
- out_rect->setHeight(rect.height() * .95);
-#endif
+ out_rect->setWidth(rect.width());
+ out_rect->setHeight(rect.height());
D("slot_getScreenDimensions: end");
}
@@ -2124,7 +2145,7 @@ void EmulatorQtWindow::slot_showWindow(SkinSurface* surface,
void EmulatorQtWindow::onScreenChanged(QScreen* newScreen) {
if (newScreen != mCurrentScreen) {
D("%s: kEventScreenChanged", __FUNCTION__);
- queueSkinEvent(createSkinEvent(kEventScreenChanged));
+ queueSkinEvent(createSkinEventScreenChanged());
mCurrentScreen = newScreen;
}
}
@@ -2135,7 +2156,7 @@ void EmulatorQtWindow::onScreenConfigChanged() {
: nullptr;
if (newScreen != mCurrentScreen) {
D("%s: kEventScreenChanged", __FUNCTION__);
- queueSkinEvent(createSkinEvent(kEventScreenChanged));
+ queueSkinEvent(createSkinEventScreenChanged());
mCurrentScreen = newScreen;
}
}
@@ -2503,7 +2524,7 @@ void EmulatorQtWindow::doResize(const QSize& size, bool isKbdShortcut) {
maskWindowFrame();
#ifdef __APPLE__
// To fix issues when resizing + linking against macos sdk 11.
- queueSkinEvent(createSkinEvent(kEventScreenChanged));
+ queueSkinEvent(createSkinEventScreenChanged());
#endif
}
@@ -3563,7 +3584,7 @@ void EmulatorQtWindow::rotateSkin(SkinRotation rot) {
#ifdef __APPLE__
{
// To fix issues when resizing + linking against macos sdk 11.
- queueSkinEvent(createSkinEvent(kEventScreenChanged));
+ queueSkinEvent(createSkinEventScreenChanged());
}
#endif
}
diff --git a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.h b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.h
index a4fcbf7bd3..722e470ca5 100644
--- a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.h
+++ b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/emulator-qt-window.h
@@ -589,6 +589,7 @@ private:
bool mWindowIsMinimized = false;
QScreen* mCurrentScreen = nullptr;
+ SkinEvent createSkinEventScreenChanged();
android::metrics::PeriodicReporter::TaskToken mMetricsReportingToken;
void saveMultidisplayToConfig();
diff --git a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/extended-window.cpp b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/extended-window.cpp
index d36483d546..2ea73475fb 100644
--- a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/extended-window.cpp
+++ b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/extended-window.cpp
@@ -495,6 +495,9 @@ void ExtendedWindow::show() {
void ExtendedWindow::showPane(ExtendedWindowPane pane) {
show();
+ if (pane == PANE_IDX_LOCATION) {
+ mExtendedUi->location_page->doWebInit();
+ }
adjustTabs(pane);
}
diff --git a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.cpp b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.cpp
index a8d9c3c695..a0122e3be9 100644
--- a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.cpp
+++ b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.cpp
@@ -486,9 +486,8 @@ void ToolWindow::on_unfold_timer_done() {
void ToolWindow::updateFoldableButtonVisibility() {
mToolsUi->change_posture_button->setEnabled(
android_foldable_hinge_enabled());
- if (mExtendedWindow.hasInstance()) {
- mExtendedWindow.get()->getVirtualSensorsPage()->updateHingeSensorUI();
- }
+ mExtendedWindow.ifExists([&] {
+ mExtendedWindow.get()->getVirtualSensorsPage()->updateHingeSensorUI(); });
}
void ToolWindow::updateButtonUiCommand(QPushButton* button,
@@ -511,8 +510,10 @@ void ToolWindow::raise() {
mVirtualSceneControlWindow.get()->raise();
}
if (mTopSwitched) {
- mExtendedWindow.get()->raise();
- mExtendedWindow.get()->activateWindow();
+ mExtendedWindow.ifExists([&] {
+ mExtendedWindow.get()->raise();
+ mExtendedWindow.get()->activateWindow();
+ });
mTopSwitched = false;
}
}
@@ -609,7 +610,7 @@ void ToolWindow::show() {
}
if (mIsExtendedWindowVisibleOnShow) {
- mExtendedWindow.get()->show();
+ mExtendedWindow.ifExists([&] { mExtendedWindow.get()->show(); });
}
}
@@ -1330,9 +1331,14 @@ bool ToolWindow::askWhetherToSaveSnapshot() {
QMessageBox msgBox(QMessageBox::Question, tr("Save quick-boot state"),
askMessage, (QMessageBox::Yes | QMessageBox::No), this);
// Add a Cancel button to enable the MessageBox's X.
- QPushButton* cancelButton = msgBox.addButton(QMessageBox::Cancel);
- // Hide the Cancel button so X is the only way to cancel.
- cancelButton->setHidden(true);
+ // Since embedded has already disconnected by this point, we always assume shutdown.
+ if(!getConsoleAgents()
+ ->settings->android_cmdLineOptions()
+ ->qt_hide_window) {
+ QPushButton* cancelButton = msgBox.addButton(QMessageBox::Cancel);
+ // Hide the Cancel button so X is the only way to cancel.
+ cancelButton->setHidden(true);
+ }
// ten seconds
constexpr int timeout = 10000;
@@ -1399,7 +1405,7 @@ void ToolWindow::on_close_button_clicked() {
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
// The user shift-clicked on the X
// This counts as us asking and having the user say "don't save"
- mExtendedWindow.get()->sendMetricsOnShutDown();
+ mExtendedWindow.ifExists([&] { mExtendedWindow.get()->sendMetricsOnShutDown(); });
mAskedWhetherToSaveSnapshot = true;
getConsoleAgents()->settings->avdParams()->flags |=
AVDINFO_NO_SNAPSHOT_SAVE_ON_EXIT;
@@ -1409,7 +1415,7 @@ void ToolWindow::on_close_button_clicked() {
}
if(shouldClose()) {
- mExtendedWindow.get()->sendMetricsOnShutDown();
+ mExtendedWindow.ifExists([&] { mExtendedWindow.get()->sendMetricsOnShutDown(); });
mEmulatorWindow->requestClose();
} else {
mAskedWhetherToSaveSnapshot = false;
@@ -1619,9 +1625,9 @@ void ToolWindow::showOrRaiseExtendedWindow(ExtendedWindowPane pane) {
return;
}
- // Set to default location pane.
+ // Set to default help pane.
if (!isPaneEnabled(pane)) {
- pane = PANE_IDX_LOCATION;
+ pane = PANE_IDX_HELP;
}
// Show the tabbed pane
mExtendedWindow.get()->showPane(pane);
@@ -1637,10 +1643,6 @@ void ToolWindow::on_more_button_clicked() {
}
}
-QRect ToolWindow::extendedWindowGeometry() {
- return mExtendedWindow.get()->frameGeometry();
-}
-
void ToolWindow::paintEvent(QPaintEvent*) {
QPainter p;
QPen pen(Qt::SolidLine);
diff --git a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.h b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.h
index da627bef98..f05e7dcb54 100644
--- a/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.h
+++ b/android/android-ui/modules/aemu-ui-qt/src/android/skin/qt/tool-window.h
@@ -142,7 +142,6 @@ public:
void hideExtendedWindow();
void waitForExtendedWindowVisibility(bool visible);
- QRect extendedWindowGeometry();
void presetSizeAdvance(PresetEmulatorSizeType newSize);
signals:
diff --git a/android/android-ui/modules/aemu-ui-window/src/android/emulator-window.c b/android/android-ui/modules/aemu-ui-window/src/android/emulator-window.c
index ee262b5240..c5b7a80ca5 100644
--- a/android/android-ui/modules/aemu-ui-window/src/android/emulator-window.c
+++ b/android/android-ui/modules/aemu-ui-window/src/android/emulator-window.c
@@ -720,6 +720,8 @@ bool emulator_window_rotate_90(bool clockwise) {
: (max_rotation + fromState - 1) % max_rotation;
assert(orientation < max_rotation && orientation >= 0);
emulator_window_set_device_coarse_orientation(orientation, 0.f);
+ // TODO(b/337038162): We really should not be dependent on virtual sensors UI, since
+ // this code can be called from non-UI code.
skin_winsys_touch_qt_extended_virtual_sensors();
return true;
}
diff --git a/android/android-ui/modules/aemu-ui-window/src/android/skin/window.c b/android/android-ui/modules/aemu-ui-window/src/android/skin/window.c
index 6cf1209f3c..6770f45360 100644
--- a/android/android-ui/modules/aemu-ui-window/src/android/skin/window.c
+++ b/android/android-ui/modules/aemu-ui-window/src/android/skin/window.c
@@ -1102,6 +1102,8 @@ struct SkinWindow {
SkinSize framebuffer;
SkinSize container;
int scroll_h; // Needed for OSX
+ // Monitor dimensions and coordinates are in logical pixels
+ SkinRect monitor;
};
const FingerState empty_touch_point_state = {0};
@@ -1640,20 +1642,12 @@ static void skin_window_ensure_fully_visible(void* ptr) {
}
/* First, we recenter the window */
- new_x = (data->monitor.size.w - data->win_w) / 2;
- new_y = (data->monitor.size.h - data->win_h) / 2;
-
- /* If it is still too large, we ensure the top-border is visible */
- if (new_y < 0)
- new_y = 0;
-
- /* If it is somehow off screen horizontally, put it back */
- if (new_x < 0)
- new_x = 0;
+ new_x = data->monitor.pos.x + (data->monitor.size.w - data->win_w) / 2;
+ new_y = data->monitor.pos.y + (data->monitor.size.h - data->win_h) / 2;
/* Don't try to put it back if the emulator is only partially too
far to the right, because that invites bouncing. */
- if (new_x >= data->monitor.size.w)
+ if ((new_x - data->monitor.pos.x) >= data->monitor.size.w)
new_x -= data->win_w;
VERBOSE_PRINT(init, "Window repositioned to [%d,%d]", new_x, new_y);
@@ -1665,6 +1659,13 @@ static void skin_window_ensure_fully_visible(void* ptr) {
AFREE(data);
}
+static void skin_window_set_monitor_rect(SkinWindow* window, int x, int y, int w, int h) {
+ window->monitor.pos.x = x;
+ window->monitor.pos.y = y;
+ window->monitor.size.w = w;
+ window->monitor.size.h = h;
+}
+
static void skin_window_set_device_pixel_ratio(SkinWindow* window) {
double dpr = 1.0;
skin_winsys_get_device_pixel_ratio(&dpr);
@@ -1715,13 +1716,14 @@ SkinWindow* skin_window_create(SkinLayout* slayout,
}
- skin_winsys_get_monitor_rect(&monitor);
- // Since monitor values are in pixel size, we need to convert it to logical size, since all
- // other values used in the below calculations are in logical pixels.
- monitor.pos.x /= window->dpr;
- monitor.pos.y /= window->dpr;
- monitor.size.w /= window->dpr;
- monitor.size.h /= window->dpr;
+ if (window->monitor.size.w == 0 || window->monitor.size.h == 0) {
+ skin_winsys_get_monitor_rect(&monitor);
+ } else {
+ monitor.pos.x = window->monitor.pos.x;
+ monitor.pos.y = window->monitor.pos.y;
+ monitor.size.w = window->monitor.size.w;
+ monitor.size.h = window->monitor.size.h;
+ }
int hw_lcd_density = getConsoleAgents()->settings->hw()->hw_lcd_density;
@@ -1929,28 +1931,40 @@ static void skin_window_resize(SkinWindow* window, int resize_container) {
}
SkinRect monitor;
- skin_winsys_get_monitor_rect(&monitor);
- // Since monitor values are in pixel size, we need to convert it to logical size, since all
- // other values used in the below calculations are in logical pixels.
- monitor.pos.x /= dpr;
- monitor.pos.y /= dpr;
- monitor.size.w /= dpr;
- monitor.size.h /= dpr;
+ if (window->monitor.size.h == 0 || window->monitor.size.w == 0) {
+ skin_winsys_get_monitor_rect(&monitor);
+ } else {
+ monitor.pos.x = window->monitor.pos.x;
+ monitor.pos.y = window->monitor.pos.y;
+ monitor.size.w = window->monitor.size.w;
+ monitor.size.h = window->monitor.size.h;
+ }
// adjust x and y to make sure it does not cause window to be out of monitor
- const int WINDOW_MINIMUM_XY = 100;
+ const int WINDOW_MINIMUM_X = monitor.pos.x + 100;
+ const int WINDOW_MINIMUM_Y = monitor.pos.y + 100;
const double WINDOW_MONITOR_RATIO = 0.9;
- if ((window_x + window_w) > WINDOW_MONITOR_RATIO * (monitor.size.w)) {
- window_x = WINDOW_MONITOR_RATIO*monitor.size.w - window_w;
- window_x = window_x > WINDOW_MINIMUM_XY ? window_x : WINDOW_MINIMUM_XY;
+ if (((window_x - monitor.pos.x) + window_w) > WINDOW_MONITOR_RATIO * (monitor.size.w)) {
+ window_x = monitor.pos.x + (WINDOW_MONITOR_RATIO*monitor.size.w - window_w);
+ window_x = window_x > WINDOW_MINIMUM_X ? window_x : WINDOW_MINIMUM_X;
window->x_pos = window_x;
+#if 0
+ // b/330777260: Moving the window while a screen change is happening may cause the window to
+ // repeatedly bounce across multiple displays. Let's disable for now until we find a real
+ // fix.
skin_winsys_set_window_pos(window_x, window_y);
+#endif // !__linux__
}
- if ((window_y + window_h) > WINDOW_MONITOR_RATIO * (monitor.size.h)) {
- window_y = WINDOW_MONITOR_RATIO*monitor.size.h - window_h;
- window_y = window_y > WINDOW_MINIMUM_XY ? window_y : WINDOW_MINIMUM_XY;
+ if (((window_y - monitor.pos.y) + window_h) > WINDOW_MONITOR_RATIO * (monitor.size.h)) {
+ window_y = monitor.pos.y + (WINDOW_MONITOR_RATIO*monitor.size.h - window_h);
+ window_y = window_y > WINDOW_MINIMUM_Y ? window_y : WINDOW_MINIMUM_Y;
window->y_pos = window_y;
+#if 0
+ // b/330777260: Moving the window while a screen change is happening may cause the window to
+ // repeatedly bounce across multiple displays. Let's disable for now until we find a real
+ // fix.
skin_winsys_set_window_pos(window_x, window_y);
+#endif // !__linux__
}
// Attempt to resize the window surface. If it doesn't exist, a new one will
// be allocated. If it does exist, but its original dimensions do not match
@@ -2722,6 +2736,9 @@ void skin_window_process_event(SkinWindow* window, SkinEvent* ev) {
// framebuffer of 2x size. Otherwise, if HiDPI is disabled, the
// framebuffer still gets the same size, but window size will be
// halved.
+ skin_window_set_monitor_rect(
+ window, ev->u.screen.x, ev->u.screen.y,
+ ev->u.screen.w, ev->u.screen.h);
skin_window_set_device_pixel_ratio(window);
skin_window_resize(window, 1);
skin_window_show_opengles(window, true);