libDtSvc: added Xinerama support to _DtMessageDialog
authoralx <alx@fastestcode.org>
Fri, 30 Dec 2016 00:21:40 +0000 (01:21 +0100)
committerJon Trulson <jon@radscan.com>
Sat, 31 Dec 2016 22:14:43 +0000 (15:14 -0700)
cde/lib/DtSvc/DtUtil2/Imakefile
cde/lib/DtSvc/DtUtil2/SharedProcs.c
cde/lib/DtSvc/Imakefile
cde/lib/DtXinerama/Imakefile
cde/lib/Imakefile

index faf13469163ba6fe703bfa62829012c4d33b7b30..522699449a7bb22a57727a3dd5ac9af62f37468a 100644 (file)
@@ -10,13 +10,18 @@ XCOMM $TOG: Imakefile /main/14 1998/04/22 14:18:31 mgreess $
 
 #include <Threads.tmpl>
 
+#if CDE_USEXINERAMA
+XINOPT = -DUSE_XINERAMA
+#endif
+
 #ifndef DtSvcDefines
 # define DtSvcDefines  -DMULTIBYTE
 #endif
 DEPEND_DEFINES = $(DEPENDDEFINES)
-DEFINES = DtSvcDefines \
+DEFINES = DtSvcDefines  $(XINOPT) \
           -DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\" \
           -DCDE_CONFIGURATION_TOP=\"$(CDE_CONFIGURATION_TOP)\"
+
 INCLUDES =  -I. -I../include
 
 #ifdef SunArchitecture
index f6a3b371f4ec736ae574466f464591b6ae6b5b62..1a5b94433851e118eb19f766a73163e40a2e29f1 100644 (file)
@@ -65,7 +65,9 @@
 #include <Dt/DtP.h>
 #include <Dt/Connect.h>
 #include <Dt/DtNlUtils.h>
-
+#ifdef USE_XINERAMA
+#include <DtXinerama.h>
+#endif
 #include "SharedProcs.h"
 
 
@@ -74,7 +76,8 @@
 
 
 /********    Static Function Declarations    ********/
-
+static void MessageDialogPopupCB(Widget w, XtPointer client_data,
+       XtPointer call_data);
 
 /********    End Static Function Declarations    ********/
 
@@ -247,17 +250,15 @@ _DtMessageDialog(
    else
       attributes.map_state = IsUnmapped;
 
+   /*
+    * If parent widget isn't mapped, attach a callback
+    * procedure that'll center the message dialog on screen.
+       */
    if (attributes.map_state == IsUnmapped)
-   {
-      XtSetArg(args[0], XmNx, (WidthOfScreen(XtScreen (w)) - 350) / 2);
-      XtSetArg(args[1], XmNy, (HeightOfScreen(XtScreen (w)) - 200) / 2);
-      XtSetArg(args[2], XmNdefaultPosition, False);
-      XtSetValues(message, args, 3);
-   }
-
+        XtAddCallback(XtParent(message),XmNpopupCallback,
+                       MessageDialogPopupCB,(XtPointer)w);
 
    /*  Adjust the decorations and title for the dialog shell of the dialog  */
-
    XtSetArg(args[0], XmNtitle, title);
    XtSetArg(args[1], XmNmwmFunctions, MWM_FUNC_MOVE);
    XtSetArg(args[2], XmNmwmDecorations, MWM_DECOR_BORDER | MWM_DECOR_TITLE);
@@ -365,4 +366,52 @@ _DtMessageClose(
    }
 }
 
-
+/*
+ * Center a message dialog on screen once it is managed.
+ * client_data is expected to contain the parent shell widget handle.
+ */
+static void MessageDialogPopupCB(Widget w, XtPointer client_data,
+       XtPointer call_data)
+{
+       Position msg_x, msg_y;
+       unsigned int scr_w, scr_h, off_x=0, off_y=0;
+       Dimension msg_w=0, msg_h=0;
+       Arg args[2];
+       #ifdef USE_XINERAMA
+       DtXineramaInfo_t *dt_xi;
+       #endif
+
+       msg_w=XtWidth(w);
+       msg_h=XtHeight(w);
+
+       scr_w=WidthOfScreen(XtScreen(w));
+       scr_h=HeightOfScreen(XtScreen(w));
+
+       #ifdef USE_XINERAMA
+       /* determine xinerama screen number the parent shell resides on,
+        * and override scr_w/scr_h and off_x/off_y on success */
+       if((dt_xi=_DtXineramaInit(XtDisplay(w)))){
+               int i;
+               unsigned int pw_x=XtX((Widget)client_data);
+               unsigned int pw_y=XtY((Widget)client_data);
+
+               for(i=0; i<dt_xi->numscreens; i++){
+                       unsigned int sw,sh,sx,sy;
+                       _DtXineramaGetScreen(dt_xi,i,&sw,&sh,&sx,&sy);
+                       if(pw_x>=sx && pw_x<(sx+sw) && pw_y>=sy && pw_y<(sy+sh)){
+                               off_x=sx; off_y=sy;
+                               scr_w=sw; scr_h=sh;
+                               break;
+                       }
+               }
+       }
+       #endif /* USE_XINERAMA */
+
+       msg_x=off_x+(scr_w-msg_w)/2;
+       msg_y=off_y+(scr_h-msg_h)/2;
+
+       XtSetArg(args[0],XmNx,msg_x);
+       XtSetArg(args[1],XmNy,msg_y);
+       XtSetValues(w,args,2);
+       XtRemoveCallback(w,XmNpopupCallback,MessageDialogPopupCB,client_data);
+}
index 3585cb8babf234cab0448f40da9e6d2e3d425f99..8ec6c3bf6e4d666412b833e9f6c68db2829329bf 100644 (file)
@@ -2,6 +2,11 @@ XCOMM $TOG: Imakefile /main/16 1998/08/10 18:02:14 mgreess $
 #define IHaveSubdirs
 #define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)' 'CXXDEBUGFLAGS=$(CXXDEBUGFLAGS)'
 
+#if CDE_USEXINERAMA
+XINOPT = -DUSE_XINERAMA
+XINLIB = -lDtXinerama -lXinerama
+#endif
+
 SUBDIRS = include DtUtil1 DtUtil2 DtEncap DtCodelibs DtXpm
 DONES = DtUtil1/DONE DtUtil2/DONE DtEncap/DONE DtCodelibs/DONE DtXpm/DONE
 EXTRALIBRARYDEPS = $(DONES)
@@ -24,18 +29,18 @@ DependSubdirs($(SUBDIRS))
 #ifndef DtSvcDefines
 # define DtSvcDefines  -DMULTIBYTE
 #endif
-DEFINES = DtSvcDefines
+DEFINES = DtSvcDefines $(XINOPT)
 
 INCLUDES = -I.
 
 #ifdef SharedDtSvcReqs
 #ifdef SunArchitecture
-REQUIREDLIBS = SharedDtSvcReqs
+REQUIREDLIBS = SharedDtSvcReqs $(XINLIB)
 #ifndef HasGcc2
 SHLIBLDFLAGS = -G
 #endif
 #else
-REQUIREDLIBS = SharedDtSvcReqs
+REQUIREDLIBS = SharedDtSvcReqs $(XINLIB)
 #endif
 #endif
 
index 21837dc45a456058929529f1493900f07baacec3..70347b43a3d46ff42405c73889a4dda4c251da7e 100644 (file)
@@ -39,5 +39,8 @@ OBJS = DtXinerama.o
 
 INCLUDES = -I.
 
+XCOMM -fpic is required for static libDtXinerama to link with libDtSvc properly
+CCOPTIONS += -fpic
+
 DependTarget()
 
index 2d0bfac8d0d6d093985a8208eecf16892c58dd8d..df37a00cc8a95cc161d1927b3821bf79657648ce 100644 (file)
@@ -12,8 +12,8 @@ PAMDIR = pam
 PAMDIR =
 #endif
 
-SUBDIRS = $(PAMDIR) tt DtSvc DtSearch DtWidget DtHelp DtPrint DtTerm DtMrm \
-       csa $(XINDIR)
+SUBDIRS = $(XINDIR) $(PAMDIR) tt DtSvc DtSearch DtWidget DtHelp DtPrint \
+       DtTerm DtMrm csa
 
 MakeSubdirs($(SUBDIRS))
 DependSubdirs($(SUBDIRS))