intel / ozone-wayland

Wayland implementation for Chromium Ozone classes
BSD 3-Clause "New" or "Revised" License
218 stars 82 forks source link

Input: implement dragging widgets with the titlebar #224

Open Tarnyko opened 10 years ago

Tarnyko commented 10 years ago

This patch build on Release branch (Milestone Valentine) and allows moving windows by dragging their titlebars.

Here, we arbitrarily consider an upper 20px surface ; but what is the window is frameless (TYPE_WINDOW_FRAMELESS) ? What's the correct way to request an Aura window type ?

Tarnyko commented 10 years ago
From 4d87943d2513e083bece4dcd126938c143e098f8 Mon Sep 17 00:00:00 2001
From: Manuel Bachmann <manuel.bachmann@open.eurogiciel.org>
Date: Thu, 20 Mar 2014 13:25:25 +0100
Subject: [PATCH] Input: Implement "surface_move" by dragging the window
 titlebar.

Change-Id: I0681acca4330344902885b2e62db3dda7b50460c
Signed-off-by: Manuel Bachmann <manuel.bachmann@open.eurogiciel.org>
---
 src/ozone/wayland/input/pointer.cc          | 14 ++++++++++++--
 src/ozone/wayland/input/pointer.h           |  1 +
 src/ozone/wayland/shell/wl_shell_surface.cc |  5 +++++
 src/ozone/wayland/shell/wl_shell_surface.h  |  1 +
 src/ozone/wayland/shell/xdg_surface.cc      |  7 +++++++
 src/ozone/wayland/shell/xdg_surface.h       |  1 +
 src/ozone/wayland/shell_surface.h           |  1 +
 src/ozone/wayland/window.cc                 |  5 +++++
 src/ozone/wayland/window.h                  |  1 +
 9 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/src/ozone/wayland/input/pointer.cc b/src/ozone/wayland/input/pointer.cc
index 848a388..012b7f4 100644
--- a/src/ozone/wayland/input/pointer.cc
+++ b/src/ozone/wayland/input/pointer.cc
@@ -15,7 +15,8 @@
 namespace ozonewayland {

 WaylandPointer::WaylandPointer()
-  : cursor_(NULL),
+  : window_(NULL),
+    cursor_(NULL),
     dispatcher_(NULL),
     pointer_position_(0, 0) {
 }
@@ -78,9 +79,14 @@ void WaylandPointer::OnButtonNotify(void* data,
   WaylandDisplay::GetInstance()->SetSerial(serial);
   WaylandInputDevice* input = WaylandDisplay::GetInstance()->PrimaryInput();
   if (input->GetFocusWindowHandle() && input->GetGrabButton() == 0 &&
-        state == WL_POINTER_BUTTON_STATE_PRESSED)
+        state == WL_POINTER_BUTTON_STATE_PRESSED) {
     input->SetGrabWindowHandle(input->GetFocusWindowHandle(), button);

+    if ((button == BTN_LEFT) &&
+        (device->pointer_position_.y() < 20.0))
+      device->window_->Move(input->GetInputSeat(), serial);
+  }
+
   if (input->GetGrabWindowHandle()) {
     ui::EventType type = ui::ET_MOUSE_PRESSED;
     if (state == WL_POINTER_BUTTON_STATE_RELEASED)
@@ -160,6 +166,8 @@ void WaylandPointer::OnPointerEnter(void* data,
   device->dispatcher_->PointerEnter(handle,
                                     device->pointer_position_.x(),
                                     device->pointer_position_.y());
+
+  device->window_ = window; 
 }

 void WaylandPointer::OnPointerLeave(void* data,
@@ -174,6 +182,8 @@ void WaylandPointer::OnPointerLeave(void* data,
                                     device->pointer_position_.x(),
                                     device->pointer_position_.y());
   input->SetFocusWindowHandle(0);
+
+  device->window_ = NULL;
 }

 }  // namespace ozonewayland
diff --git a/src/ozone/wayland/input/pointer.h b/src/ozone/wayland/input/pointer.h
index fee6dbe..7d51092 100644
--- a/src/ozone/wayland/input/pointer.h
+++ b/src/ozone/wayland/input/pointer.h
@@ -59,6 +59,7 @@ class WaylandPointer {
       uint32_t serial,
       wl_surface* surface);

+  WaylandWindow* window_;
   WaylandCursor* cursor_;
   EventConverterOzoneWayland* dispatcher_;
   // Keeps track of the last position for the motion event. We want to
diff --git a/src/ozone/wayland/shell/wl_shell_surface.cc b/src/ozone/wayland/shell/wl_shell_surface.cc
index 39136f6..07c9066 100644
--- a/src/ozone/wayland/shell/wl_shell_surface.cc
+++ b/src/ozone/wayland/shell/wl_shell_surface.cc
@@ -73,6 +73,11 @@ void WLShellSurface::Maximize() {
 void WLShellSurface::Minimize() {
 }

+void WLShellSurface::Move(struct wl_seat *seat,
+                          uint32_t serial) {
+  wl_shell_surface_move(shell_surface_, seat, serial);
+}
+
 void WLShellSurface::HandleConfigure(void *data,
                                           struct wl_shell_surface *surface,
                                           uint32_t edges,
diff --git a/src/ozone/wayland/shell/wl_shell_surface.h b/src/ozone/wayland/shell/wl_shell_surface.h
index c5d2ff2..3c6f2ae 100644
--- a/src/ozone/wayland/shell/wl_shell_surface.h
+++ b/src/ozone/wayland/shell/wl_shell_surface.h
@@ -24,6 +24,7 @@ class WLShellSurface : public WaylandShellSurface {
   virtual void SetWindowTitle(const base::string16& title) OVERRIDE;
   virtual void Maximize() OVERRIDE;
   virtual void Minimize() OVERRIDE;
+  virtual void Move(struct wl_seat* seat, uint32_t serial) OVERRIDE;

   static void HandleConfigure(void* data,
                               struct wl_shell_surface* shell_surface,
diff --git a/src/ozone/wayland/shell/xdg_surface.cc b/src/ozone/wayland/shell/xdg_surface.cc
index 0773d35..c8c5716 100644
--- a/src/ozone/wayland/shell/xdg_surface.cc
+++ b/src/ozone/wayland/shell/xdg_surface.cc
@@ -94,6 +94,13 @@ void XDGSurface::Minimize() {
   IsMinimized = true;
 }

+void XDGSurface::Move(struct wl_seat *seat,
+                      uint32_t serial)
+{
+  xdg_surface_move(xdg_surface_, seat, serial);
+  WaylandShellSurface::PopupDone();
+}
+
 void XDGSurface::HandleConfigure(void* data,
                                  struct xdg_surface* xdg_surface,
                                  uint32_t edges,
diff --git a/src/ozone/wayland/shell/xdg_surface.h b/src/ozone/wayland/shell/xdg_surface.h
index 8f3b680..b044cf6 100644
--- a/src/ozone/wayland/shell/xdg_surface.h
+++ b/src/ozone/wayland/shell/xdg_surface.h
@@ -25,6 +25,7 @@ class XDGSurface : public WaylandShellSurface {
   virtual void SetWindowTitle(const base::string16& title) OVERRIDE;
   virtual void Maximize() OVERRIDE;
   virtual void Minimize() OVERRIDE;
+  virtual void Move(struct wl_seat *seat, uint32_t serial) OVERRIDE;

   static void HandleConfigure(void* data,
                               struct xdg_surface* xdg_surface,
diff --git a/src/ozone/wayland/shell_surface.h b/src/ozone/wayland/shell_surface.h
index 02ad672..297acf6 100644
--- a/src/ozone/wayland/shell_surface.h
+++ b/src/ozone/wayland/shell_surface.h
@@ -33,6 +33,7 @@ class WaylandShellSurface {
   virtual void SetWindowTitle(const base::string16& title) = 0;
   virtual void Maximize() = 0;
   virtual void Minimize() = 0;
+  virtual void Move(struct wl_seat* seat, uint32_t serial) = 0;
   //static functions
   static void PopupDone();
   static void WindowResized(void *data, unsigned width, unsigned height);
diff --git a/src/ozone/wayland/window.cc b/src/ozone/wayland/window.cc
index 38edec6..e7a360a 100644
--- a/src/ozone/wayland/window.cc
+++ b/src/ozone/wayland/window.cc
@@ -82,6 +82,11 @@ void WaylandWindow::SetFullscreen() {
     shell_surface_->UpdateShellSurface(FULLSCREEN, NULL, 0, 0);
 }

+void WaylandWindow::Move(struct wl_seat* seat, uint32_t serial) {
+  if (type_ != FULLSCREEN)
+    shell_surface_->Move(seat, serial);
+}
+
 void WaylandWindow::RealizeAcceleratedWidget() {
   if (!shell_surface_) {
     LOG(ERROR) << "Shell type not set. Setting it to TopLevel";
diff --git a/src/ozone/wayland/window.h b/src/ozone/wayland/window.h
index 0a8326c..b2d284f 100644
--- a/src/ozone/wayland/window.h
+++ b/src/ozone/wayland/window.h
@@ -43,6 +43,7 @@ class WaylandWindow {
   void Minimize();
   void Restore();
   void SetFullscreen();
+  void Move(struct wl_seat* seat, uint32_t serial);

   ShellType Type() const { return type_; }
   unsigned Handle() const { return handle_; }
-- 
1.8.1.4
kalyankondapally commented 10 years ago

@Tarnyko Reg (TYPE_WINDOW_FRAMELESS), WaylandWIndow should have this information and one should be able to query this from it. We need a proper integration of drag and drop support, but I see this as the initial step towards it. Check DesktopDragDropClientWayland in ui/desktop_aura

tiagovignatti commented 10 years ago

indeed.

Although basic window move seems fairly easy to get it working, seems that the corner cases of having it are quite complex. I'd suggest you to study the X11 code as well, looking for things like aura::client::WindowMoveClient: https://code.google.com/p/chromium/codesearch#chromium/src/ui/aura/client/window_move_client.h&q=windowmoveclient&sq=package:chromium&l=31

and the way that X11 implements it on views::X11DesktopWindowMoveClient: https://code.google.com/p/chromium/codesearch#chromium/src/ui/views/widget/desktop_aura/x11_desktop_window_move_client.h&sq=package:chromium&rcl=1395338115&l=31

Tarnyko commented 10 years ago

@kalyankondapally Thanks ! This parameter seems to be sent to the Aura Window, without any function to get it back. I have the impression I need to write helper functions from Chromium down to Ozone to get it. Will work on this.

@tiagovignatti Thanks, will look at this.

kalyankondapally commented 10 years ago

@Tarnyko not sure if I understand your comment correctly.

check InitWaylandWindow in ui/desktop_aura/desktop_window_tree_host_wayland.cc, case Widget::InitParams::TYPE_WINDOW_FRAMELESS is not implemented. I see that as the only missing link here.

kalyankondapally commented 10 years ago

@Tarnyko Please check the instructions here https://github.com/01org/ozone-wayland/wiki/Collaborating-and-Submitting-Changes
It's hard to review and give feedback in this manner.

kalyankondapally commented 10 years ago

@Tarnyko Are you looking into this still ?