gui: add "window_position" startup option as optional parameter
authorGiWoong Kim <giwoong.kim@samsung.com>
Tue, 8 Mar 2016 08:25:16 +0000 (17:25 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 16 Mar 2016 10:17:07 +0000 (19:17 +0900)
Open the emulator window at given position if qemu has a
"window_position" variable in startup options.
ex) emulator-x86.sh .../vm_launch.conf --window_position 100,100

Change-Id: I935ffea3e7aa67ccfa30a8152a1aacab275bf0e7
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/mainwindow.cpp
tizen/src/ui/mainwindow.h
tizen/src/ui/qt5_supplement.cpp

index 5a21f18ca12adcb7b80dcdba79921208d597667e..dd8a5d02ef8450735bc8b7ff7c6a449ac8facebb 100644 (file)
@@ -398,16 +398,7 @@ void MainWindow::resizeEvent(QResizeEvent *event)
     QWidget::resizeEvent(event);
     setFixedSize(size());
 
-    /* correctional position */
-    int xx = pos().x();
-    int yy = pos().y();
-    QRect hostBounds = UiUtil::getHostScreenBounds();
-    xx = qMax(xx, hostBounds.x());
-    yy = qMax(yy, hostBounds.y());
-    // shift a little bit from screen edge to inside of bounds
-    xx = qMin(xx, hostBounds.x() + hostBounds.width() - 100);
-    yy = qMin(yy, hostBounds.y() + hostBounds.height() - 100);
-    move(xx, yy);
+    calibratedMove(pos().x(), pos().y());
 }
 
 /* override */
@@ -547,6 +538,20 @@ void MainWindow::setTopMost(bool on)
     popupMenu->slotOnTop(on);
 }
 
+void MainWindow::calibratedMove(int xx, int yy)
+{
+    QRect hostBounds = UiUtil::getHostScreenBounds();
+
+    xx = qMax(xx, hostBounds.x());
+    yy = qMax(yy, hostBounds.y());
+    // shift a little bit from screen edge to inside of bounds
+    xx = qMin(xx, hostBounds.x() + hostBounds.width() - 100);
+    yy = qMin(yy, hostBounds.y() + hostBounds.height() - 100);
+
+    move(xx, yy);
+    qDebug() << "current position:" << pos();
+}
+
 void MainWindow::turnOnMovingMode()
 {
     qDebug("enter the moving mode");
index 7cfbd8e1c8685ba04e23de8cb1434b3d834df93b..183aeb337c370e2036ebc0e0917181972929e51f 100644 (file)
@@ -73,6 +73,7 @@ public:
     void unsetCaptureRequestHandler(void *data);
     void processCaptured(bool captured, void *pixels, int width, int height);
     void setTopMost(bool on);
+    void calibratedMove(int x, int y);
 
     DockingController *getDockingCon();
     FloatingController *getFloatingCon();
index f3346e23f3e026cac1439565f52a6290db349cfc..4df02d7634c29eb9786d4e0e3734c8e5a200ab63 100644 (file)
@@ -41,6 +41,8 @@
 
 extern "C" {
 #include "emul_state.h"
+#include "emulator_options.h"
+
 int qemu_get_thread_id(void);
 bool is_display_off(void);
 }
@@ -210,28 +212,32 @@ static void qt5_gui_init(void)
     mainwindow->setCaptureRequestHandler(captureRequestListener, captureRequestHandler);
 
     /* position */
-    QRect hostBounds = UiUtil::getHostScreenBounds();
-    qDebug() << "host geometry:" << hostBounds;
+    int xx = 0;
+    int yy = 0;
 
-    int defaultValueX = hostBounds.x() - 1;
-    int defaultValueY = hostBounds.y() - 1;
-    int xx = mruInfo.value(SKIN_PROPERTY_WINDOW_X, defaultValueX).toInt();
-    int yy = mruInfo.value(SKIN_PROPERTY_WINDOW_Y, defaultValueY).toInt();
+    const char *winPosOpt = get_variable("window_position");
+    if (winPosOpt != NULL) {
+        qDebug("window_position option was found");
 
-    if (xx == defaultValueX || yy == defaultValueY) {
-        xx = yy = 80 + (uiInfo->getBasePort() % 100); /* default position */
+        char *endptr = NULL;
+        xx = (int)g_ascii_strtoll(winPosOpt, &endptr, 10);
+        yy = (int)g_ascii_strtoll(++endptr, &endptr, 10);
     } else {
-        qDebug("previous position: (%d, %d)", xx, yy);
+        const int defaultPos = 80;
 
-        xx = qMax(xx, hostBounds.x());
-        xx = qMin(xx, hostBounds.x() + hostBounds.width() - 100);
-        yy = qMax(yy, hostBounds.y());
-        yy = qMin(yy, hostBounds.y() + hostBounds.height() - 100);
+        if (mruInfo.contains(SKIN_PROPERTY_WINDOW_X) == true &&
+            mruInfo.contains(SKIN_PROPERTY_WINDOW_Y) == true) {
+            xx = mruInfo.value(SKIN_PROPERTY_WINDOW_X, defaultPos).toInt();
+            yy = mruInfo.value(SKIN_PROPERTY_WINDOW_Y, defaultPos).toInt();
+        } else {
+            /* differential position for each VM */
+            xx = yy = defaultPos + (uiInfo->getBasePort() % 100);
+        }
     }
 
-    mainwindow->move(xx, yy);
-    qDebug("current position: (%d, %d)", xx, yy);
+    mainwindow->calibratedMove(xx, yy);
 
+    /* z-order */
     bool onTop = mruInfo.value(SKIN_PROPERTY_WINDOW_TOPMOST).toBool();
     if (onTop == true) {
         mainwindow->setTopMost(true);