Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
justforlxz committed Dec 28, 2023
1 parent 48647dd commit 4e91870
Show file tree
Hide file tree
Showing 17 changed files with 746 additions and 2 deletions.
59 changes: 59 additions & 0 deletions src/treeland/data/treeland-foreign-toplevel-manager-v1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
the client should free any resources associated with it.
</description>
</event>
<request name="get_dock_preview_context">
<arg name="relative_surface" type="object" interface="wl_surface" />
<arg name="id" type="new_id" interface="treeland_dock_preview_context_v1" />
</request>
</interface>
<interface name="ztreeland_foreign_toplevel_handle_v1" version="1">
<description summary="An opened toplevel">
Expand Down Expand Up @@ -290,4 +294,59 @@
allow-null="true" />
</event>
</interface>
<interface name="treeland_dock_preview_context_v1" version="1">
<description summary="handle dock preview">
This interface allows dock set windows preview.

Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
</description>

<enum name="direction">
<description summary="types of direction on the dock preview">
</description>

<entry name="top" value="0" summary="top" />
<entry name="right" value="1" summary="right" />
<entry name="bottom" value="2" summary="bottom" />
<entry name="left" value="3" summary="left" />
</enum>

<event name="enter">
<description summary="enter preview box">
This event is sent after mouse enter preview box.
</description>
</event>
<event name="leave">
<description summary="leave preview box">
This event is sent after mouse leave preview box.
</description>
</event>

<request name="show">
<description summary="set preview surfaces">
X and Y are relative to the relative_surface.
surfaces wl_array is identifiers.
</description>

<arg name="surfaces" type="array" />
<arg name="x" type="int" />
<arg name="y" type="int" />
<arg name="direction" type="uint" />
</request>

<request name="close">
<description summary="close preview box">
close preview box
</description>
</request>

<request name="destroy" type="destructor">
<description summary="destroy the context object">
Destroy the context object.
</description>
</request>
</interface>
</protocol>
1 change: 1 addition & 0 deletions src/treeland/protocols/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ target_sources(treeland-protocols PRIVATE
personalizationwallpapercontext.cpp
personalizationmanager.cpp
qshortcutmanager.cpp
dockpreviewcontextv1.cpp
)

target_compile_definitions(treeland-protocols
Expand Down
99 changes: 99 additions & 0 deletions src/treeland/protocols/dockpreviewcontextv1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (C) 2023 Dingyuan Zhang <[email protected]>.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only


#include "foreigntoplevelhandlev1.h"
#include "foreign_toplevel_manager_impl.h"

#include <QHash>

#include <qwoutput.h>
#include <qwsignalconnector.h>
#include <qwglobal.h>

QW_USE_NAMESPACE

class TreeLandDockPreviewContextV1Private : public QWObjectPrivate
{
public:
TreeLandDockPreviewContextV1Private(treeland_dock_preview_context_v1 *handle, bool isOwner, TreeLandDockPreviewContextV1 *qq)
: QWObjectPrivate(handle, isOwner, qq)
{
Q_ASSERT(!map.contains(handle));
map.insert(handle, qq);
sc.connect(&handle->events.destroy, this, &TreeLandDockPreviewContextV1Private::on_destroy);
sc.connect(&handle->events.request_show, this, &TreeLandDockPreviewContextV1Private::on_request_show);
sc.connect(&handle->events.request_close, this, &TreeLandDockPreviewContextV1Private::on_request_close);
}
~TreeLandDockPreviewContextV1Private() {
if (!m_handle)
return;
destroy();
if (isHandleOwner)
treeland_dock_preview_context_v1_destroy(q_func()->handle());
}

inline void destroy() {
Q_ASSERT(m_handle);
Q_ASSERT(map.contains(m_handle));
Q_EMIT q_func()->beforeDestroy(q_func());
map.remove(m_handle);
sc.invalidate();
}

void on_destroy(void *);
void on_request_show(void *);
void on_request_close(void *);

static QHash<void*, TreeLandDockPreviewContextV1*> map;
QW_DECLARE_PUBLIC(TreeLandDockPreviewContextV1)

Check warning on line 49 in src/treeland/protocols/dockpreviewcontextv1.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If QW_DECLARE_PUBLIC is a macro then please configure it.
QWSignalConnector sc;
};
QHash<void*, TreeLandDockPreviewContextV1*> TreeLandDockPreviewContextV1Private::map;

void TreeLandDockPreviewContextV1Private::on_destroy(void *)
{
destroy();
m_handle = nullptr;
delete q_func();
}

void TreeLandDockPreviewContextV1Private::on_request_show(void *data)
{
struct treeland_dock_preview_context_v1_preview_event *event = static_cast<treeland_dock_preview_context_v1_preview_event*>(data);
Q_EMIT q_func()->requestShow(event);
}

void TreeLandDockPreviewContextV1Private::on_request_close([[maybe_unused]] void *data)
{
Q_EMIT q_func()->requestClose();
}

TreeLandDockPreviewContextV1::TreeLandDockPreviewContextV1(treeland_dock_preview_context_v1 *handle, bool isOwner)
: QObject(nullptr)
, QWObject(*new TreeLandDockPreviewContextV1Private(handle, isOwner, this))
{

}

TreeLandDockPreviewContextV1 *TreeLandDockPreviewContextV1::get(treeland_dock_preview_context_v1 *handle)
{
return TreeLandDockPreviewContextV1Private::map.value(handle);
}

TreeLandDockPreviewContextV1 *TreeLandDockPreviewContextV1::from(treeland_dock_preview_context_v1 *handle)
{
if (auto o = get(handle))
return o;
return new TreeLandDockPreviewContextV1(handle, false);
}

void TreeLandDockPreviewContextV1::enter()
{
treeland_dock_preview_context_v1_enter(handle());
}

void TreeLandDockPreviewContextV1::leave()
{
treeland_dock_preview_context_v1_leave(handle());
}
Loading

0 comments on commit 4e91870

Please sign in to comment.