M7S / dockbarx

287 stars 40 forks source link

dockbarx for lxqt #66

Open candrapersada opened 6 years ago

candrapersada commented 6 years ago

add Embed DockbarX in the lxqt-panel

M7S commented 4 years ago

Can you even make a third party lxqt-panel plugins? My (very short) research into lxqt-panel makes me believe that all plugins are part of the source code for the panel. https://github.com/lxqt/lxqt-panel

xuzhen commented 4 years ago

Yes, It's possible. Here's my PoC plugin screenshot example

CesarSalazar885 commented 4 years ago

Yes, It's possible. Here's my PoC plugin screenshot example

Wow. It looks good. How did you do it?

xuzhen commented 4 years ago

First run a standalone python program which contains dockbarx, and pass the top window id of itself to the Qt codes. Then call QWindow::fromWinId and QWidget::createWindowContainer to create the plugin widget

container.py:

import dockbarx.dockbar
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

class DockBarPlug(Gtk.Window):
    def __init__ (self):
        Gtk.Window.__init__(self)
        #self.get_settings().connect("notify::gtk-theme-name",self.theme_changed)
        self.__realize_sid = self.connect("realize",self.__on_realize)

        self.dockbar = dockbarx.dockbar.DockBar(self)
        self.dockbar.set_orient("down")
        self.dockbar.load()
        self.add(self.dockbar.get_container())
        self.dockbar.set_size(22)
        self.show_all()

    def __on_realize(self, widget):
        self.disconnect(self.__realize_sid)
        self.__realize_sid = None
        xid = self.get_window().get_xid()
        print(xid)

    def destroy (self, widget, data=None):
        Gtk.main_quit()

if __name__ == '__main__':
    dbx = DockBarPlug()
    Gtk.main()

dockbarqt.cpp:

#include "dockbarqt.h"
#include <QWindow>
#include <QDebug>

DockbarQt::DockbarQt(const ILXQtPanelPluginStartupInfo &startupInfo) :
    QObject(),
    ILXQtPanelPlugin(startupInfo)
{
    realign();
}

QWidget *DockbarQt::widget() {
    QWindow *win = QWindow::fromWinId(_THE_WINDOW_ID_FROM_PYTHON_CODE_);
    QWidget *widget = QWidget::createWindowContainer(win, nullptr);
    widget->show();
    return widget;
}

void DockbarQt::realign()
{
    qDebug() << panel()->iconSize();
}

dockbarqt.h:

#ifndef DOCKBARQT_H
#define DOCKBARQT_H

#include <QObject>
#include <QtWidgets/QFrame>
#include <QtWidgets/QWidget>
#include <QString>
#include <lxqt/ilxqtpanel.h>
#include <lxqt/ilxqtpanelplugin.h>
#include <lxqt/lxqtpanelglobals.h>
#include <lxqt/pluginsettings.h>

class DockbarQt : public QObject, public ILXQtPanelPlugin
{
    Q_OBJECT
public:
    DockbarQt(const ILXQtPanelPluginStartupInfo &startupInfo);

    virtual QWidget *widget();
    virtual QString themeId() const { return QStringLiteral("DockbarQt"); }
    bool isSeparate() const { return true; }
    bool isExpandable() const { return true; }
    void realign();
};

class DockbarQtLibrary: public QObject, public ILXQtPanelPluginLibrary
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "lxqt.org/Panel/PluginInterface/3.0")
    Q_INTERFACES(ILXQtPanelPluginLibrary)
public:
    ILXQtPanelPlugin *instance(const ILXQtPanelPluginStartupInfo &startupInfo) const
    {
        return new DockbarQt(startupInfo);
    }
};

#endif // DOCKBARQT_H
xuzhen commented 10 months ago

The LXQt panel plugin is here: https://github.com/xuzhen/dockbarx-lxqt-plugin