From 86a9471a49214ff49375290bb8d23d7180556277 Mon Sep 17 00:00:00 2001
From: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
Date: Fri, 16 Oct 2026 15:00:23 -0300
Subject: Skip GLib polling with native TQt integration
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
---
 ConfigureChecks.cmake | 11 ++++++++---
 src/CMakeLists.txt    | 13 ++++++++++---
 src/main.cpp          |  7 ++++++-
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 5aadb6d..a4656c9 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -32,8 +32,13 @@ if( NOT POLKIT_TQT_FOUND )
   tde_message_fatal( "polkit-tqt is required, but was not found on your system" )
 endif( )
 
-pkg_search_module( GLIB2 glib-2.0 )
-if( NOT GLIB2_FOUND )
-  tde_message_fatal( "glib-2.0 is required, but was not found on your system" )
+pkg_get_variable( TQT_CONFIG tqt-mt qt_config )
+if( "glibmainloop" IN_LIST TQT_CONFIG )
+  set( POLKIT_AGENT_TQT_GLIBMAINLOOP TRUE )
+else( )
+  pkg_search_module( GLIB2 glib-2.0 )
+  if( NOT GLIB2_FOUND )
+    tde_message_fatal( "glib-2.0 is required, but was not found on your system" )
+  endif( )
 endif( )
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e3f4bc4..269791e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,14 +19,20 @@ include_directories(
   ${TQT_INCLUDE_DIRS}
   ${TDE_INCLUDE_DIR}
   ${POLKIT_TQT_INCLUDE_DIRS}
-  ${GLIB2_INCLUDE_DIRS}
 )
 
 link_directories(
   ${TQT_LIBRARY_DIRS}
-  ${GLIB2_LIBRARY_DIRS}
 )
 
+if( POLKIT_AGENT_TQT_GLIBMAINLOOP )
+  add_definitions( -DPOLKIT_AGENT_TQT_GLIBMAINLOOP )
+else( )
+  include_directories( ${GLIB2_INCLUDE_DIRS} )
+  link_directories( ${GLIB2_LIBRARY_DIRS} )
+  set( POLKIT_AGENT_GLIB_LIBRARIES ${GLIB2_LIBRARIES} )
+endif( )
+
 
 ##### autostart file #####
 
@@ -40,6 +46,7 @@ tde_create_translated_desktop(
 tde_add_executable( polkit-agent-tde AUTOMOC
   SOURCES AuthDialogWidget.ui AuthDetailsWidget.ui AuthDialog.h AuthDialog.cpp
           polkit-listener.h polkit-listener.cpp polkit-agent-tde.h polkit-agent-tde.cpp main.cpp
-  LINK tdecore-shared tdeui-shared polkit-tqt-agent-shared ${GLIB2_LIBRARIES}
+  LINK tdecore-shared tdeui-shared polkit-tqt-agent-shared
+       ${POLKIT_AGENT_GLIB_LIBRARIES}
   DESTINATION ${BIN_INSTALL_DIR}
 )
diff --git a/src/main.cpp b/src/main.cpp
index 414f029..e194f86 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,12 +21,14 @@
 #include <tdeaboutdata.h>
 #include <tdecmdlineargs.h>
 #include <tdelocale.h>
+#ifndef POLKIT_AGENT_TQT_GLIBMAINLOOP
 #include <tqeventloop.h>
-
 #include <glib.h>
+#endif
 
 #include "polkit-agent-tde.h"
 
+#ifndef POLKIT_AGENT_TQT_GLIBMAINLOOP
 class PolkitAgentEventLoop : public TQEventLoop
 {
 public:
@@ -42,10 +44,13 @@ public:
     return glibProcessed || tqtProcessed;
   }
 };
+#endif
 
 int main(int argc, char *argv[])
 {
+#ifndef POLKIT_AGENT_TQT_GLIBMAINLOOP
   PolkitAgentEventLoop glibEventLoop;
+#endif
 
   TDEAboutData aboutData("polkit-agent-tde", I18N_NOOP("Polkit-Agent-TDE"), "0.99.1",
           I18N_NOOP("A Polkit authentication agent for TDE"), TDEAboutData::License_GPL,
-- 
cgit v1.2.3

