From b14b3a3026ee97824cebd42c83945d0cf9ac6f74 Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Wed, 30 Jan 2019 23:53:23 +0300
Subject: Fix build on Haiku


diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1ca95be..1bd66fc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,7 +23,9 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
 find_package(Qt5DBus ${QT_MINIMUM_VERSION} REQUIRED)
 find_package(Qt5LinguistTools ${QT_MINIMUM_VERSION} REQUIRED)
 find_package(Qt5Widgets ${QT_MINIMUM_VERSION} REQUIRED)
-find_package(Qt5X11Extras ${QT_MINIMUM_VERSION} REQUIRED)
+if (UNIX AND NOT HAIKU)
+	find_package(Qt5X11Extras "${REQUIRED_QT_VERSION}" REQUIRED)
+endif()
 find_package(fm-qt ${LIBFMQT_MINIMUM_VERSION} REQUIRED)
 find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
 
diff --git a/pcmanfm/CMakeLists.txt b/pcmanfm/CMakeLists.txt
index 66a56c6..90dc024 100644
--- a/pcmanfm/CMakeLists.txt
+++ b/pcmanfm/CMakeLists.txt
@@ -75,13 +75,20 @@ target_include_directories(pcmanfm-qt
         "${Qt5Gui_PRIVATE_INCLUDE_DIRS}"
 )
 
+if(UNIX AND NOT HAIKU)
+target_link_libraries(pcmanfm-qt Qt5::X11Extras)
+endif()
+
 target_link_libraries(pcmanfm-qt
-    Qt5::X11Extras
     Qt5::Widgets
     Qt5::DBus
     fm-qt
 )
 
+if(HAIKU)
+    target_link_libraries(pcmanfm-qt network)
+endif ()
+
 install(TARGETS pcmanfm-qt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 
 # install a desktop entry file for pcmanfm-qt and desktop preferences
diff --git a/pcmanfm/application.cpp b/pcmanfm/application.cpp
index 0e7950d..b8fa8c0 100644
--- a/pcmanfm/application.cpp
+++ b/pcmanfm/application.cpp
@@ -52,9 +52,9 @@
 #include "launcher.h"
 #include "xdgdir.h"
 #include "connectserverdialog.h"
-
-#include <X11/Xlib.h>
-
+#ifndef Q_OS_HAIKU
+ #include <X11/Xlib.h>
+#endif
 
 namespace PCManFM {
 
diff --git a/pcmanfm/desktopwindow.cpp b/pcmanfm/desktopwindow.cpp
index 583b680..e5844dd 100644
--- a/pcmanfm/desktopwindow.cpp
+++ b/pcmanfm/desktopwindow.cpp
@@ -55,10 +55,13 @@
 #include "xdgdir.h"
 #include "bulkrename.h"
 
-#include <QX11Info>
+#ifndef Q_OS_HAIKU
+ #include <QX11Info>
+ #include <X11/Xlib.h>
+#endif
+
 #include <QScreen>
 #include <xcb/xcb.h>
-#include <X11/Xlib.h>
 
 #define WORK_AREA_MARGIN 12 // margin of the work area
 #define MIN_SLIDE_INTERVAL 5*60000 // 5 min
@@ -1388,6 +1391,7 @@ void DesktopWindow::onFilePropertiesActivated() {
     }
 }
 
+#ifndef Q_OS_HAIKU
 static void forwardMouseEventToRoot(QMouseEvent* event) {
     xcb_ungrab_pointer(QX11Info::connection(), event->timestamp());
     // forward the event to the root window
@@ -1453,8 +1457,12 @@ static void forwardMouseEventToRoot(QMouseEvent* event) {
     xcb_send_event(QX11Info::connection(), 0, root, mask, (char*)&xcb_event);
     xcb_flush(QX11Info::connection());
 }
+#endif
 
 bool DesktopWindow::event(QEvent* event) {
+#ifdef Q_OS_HAIKU
+	return 0;
+#elif
     switch(event->type()) {
     case QEvent::WinIdChange: {
         //qDebug() << "winid change:" << effectiveWinId();
@@ -1472,7 +1480,9 @@ bool DesktopWindow::event(QEvent* event) {
             xcb_change_property(con, XCB_PROP_MODE_REPLACE, effectiveWinId(), prop_atom, XA_ATOM, 32, 1, &atom);
         }
         break;
+#endif
     }
+#ifndef Q_OS_HAIKU
 #undef FontChange // FontChange is defined in the headers of XLib and clashes with Qt, let's undefine it.
     case QEvent::StyleChange:
     case QEvent::FontChange:
@@ -1487,8 +1497,12 @@ bool DesktopWindow::event(QEvent* event) {
 }
 
 #undef FontChange // this seems to be defined in Xlib headers as a macro, undef it!
+#endif
 
 bool DesktopWindow::eventFilter(QObject* watched, QEvent* event) {
+#ifdef Q_OS_HAIKU
+	return 0;
+#elif
     if(watched == listView_) {
         switch(event->type()) {
         case QEvent::StyleChange:
@@ -1529,6 +1543,7 @@ bool DesktopWindow::eventFilter(QObject* watched, QEvent* event) {
         }
     }
     return Fm::FolderView::eventFilter(watched, event);
+#endif
 }
 
 void DesktopWindow::childDragMoveEvent(QDragMoveEvent* e) {
-- 
2.19.1


From 6104d9e86bf0eb467734bd1cc178712480b3bee0 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 31 Jan 2019 18:33:50 +1000
Subject: Disable DBUS for Haiku


diff --git a/pcmanfm/application.cpp b/pcmanfm/application.cpp
index b8fa8c0..dc745c9 100644
--- a/pcmanfm/application.cpp
+++ b/pcmanfm/application.cpp
@@ -21,8 +21,10 @@
 #include "application.h"
 #include "mainwindow.h"
 #include "desktopwindow.h"
+#ifndef __HAIKU__
 #include <QDBusConnection>
 #include <QDBusInterface>
+#endif
 #include <QDir>
 #include <QVector>
 #include <QLocale>
@@ -87,7 +89,7 @@ Application::Application(int& argc, char** argv):
     argv_ = argv;
 
     setApplicationVersion(PCMANFM_QT_VERSION);
-
+#ifndef __HAIKU__
     // QDBusConnection::sessionBus().registerObject("/org/pcmanfm/Application", this);
     QDBusConnection dbus = QDBusConnection::sessionBus();
     if(dbus.registerService(serviceName)) {
@@ -123,6 +125,12 @@ Application::Application(int& argc, char** argv):
         // we're not the first instance
         isPrimaryInstance = false;
     }
+#else
+	isPrimaryInstance = true;
+	setStyle(new ProxyStyle());
+	connect(this, &Application::aboutToQuit, this, &Application::onAboutToQuit);
+	installSigtermHandler();
+#endif
 }
 
 Application::~Application() {
@@ -260,6 +268,7 @@ bool Application::parseCommandLineArgs() {
             }
         }
     }
+#ifndef __HAIKU__
     else {
         QDBusConnection dbus = QDBusConnection::sessionBus();
         QDBusInterface iface(serviceName, "/Application", ifaceName, dbus, this);
@@ -297,6 +306,7 @@ bool Application::parseCommandLineArgs() {
             }
         }
     }
+#endif
     return keepRunning;
 }
 
-- 
2.19.1


From f641b107d39168c5c2e1a644c6486bd8a2e45d51 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 31 Jan 2019 18:34:26 +1000
Subject: Dirty hack for fix crash on exit


diff --git a/pcmanfm/pcmanfm.cpp b/pcmanfm/pcmanfm.cpp
index fa57d3e..7da5641 100644
--- a/pcmanfm/pcmanfm.cpp
+++ b/pcmanfm/pcmanfm.cpp
@@ -1,6 +1,12 @@
 #include "application.h"
 #include <libfm-qt/libfmqt.h>
 
+#ifdef __HAIKU__
+#include <unistd.h>
+#include <sys/types.h>
+#include <signal.h>
+#endif
+
 int main(int argc, char** argv) {
     // ensure that glib integration of Qt is not turned off
     // This fixes #168: https://github.com/lxqt/pcmanfm-qt/issues/168
@@ -10,5 +16,11 @@ int main(int argc, char** argv) {
     app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
 
     app.init();
+#ifdef __HAIKU__
+	app.exec();
+	kill(::getpid(), SIGKILL);
+	return 0;
+#else
     return app.exec();
+#endif
 }
-- 
2.19.1


From 3793befe2075cec3d0143324bf0413caade57117 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 31 Jan 2019 18:35:04 +1000
Subject: Remove Root Instance warning


diff --git a/pcmanfm/mainwindow.cpp b/pcmanfm/mainwindow.cpp
index 9914451..1850ea1 100644
--- a/pcmanfm/mainwindow.cpp
+++ b/pcmanfm/mainwindow.cpp
@@ -135,7 +135,7 @@ MainWindow::MainWindow(Fm::FilePath path):
     setAttribute(Qt::WA_DeleteOnClose);
     // setup user interface
     ui.setupUi(this);
-
+#ifndef __HAIKU__
     // add a warning label to the root instance
     if(geteuid() == 0) {
         QLabel *warningLabel = new QLabel(tr("Root Instance"));
@@ -145,7 +145,7 @@ MainWindow::MainWindow(Fm::FilePath path):
         ui.verticalLayout->addWidget(warningLabel);
         ui.verticalLayout->setStretch(0, 1);
     }
-
+#endif
     splitView_ = settings.splitView();
 
     // hide menu items that are not usable
-- 
2.19.1

