File xpdf-poppler-settitle.patch of Package xpdf-poppler

--- BUILD/xpdf-3.02-poppler/XPDFViewer.cc
+++ BUILD/xpdf-3.02-poppler/XPDFViewer.cc
@@ -20,6 +20,10 @@
 #ifdef HAVE_X11_XPM_H
 #include <X11/xpm.h>
 #endif
+#include <locale.h>
+#include <langinfo.h>
+#include <iconv.h>
+#include <X11/Xatom.h>
 #if defined(__sgi) && (XmVERSION <= 1)
 #define Object XtObject
 #include <Sgm/HPanedW.h>
@@ -255,7 +259,8 @@
   outlineLabelsLength = outlineLabelsSize = 0;
   outlinePaneWidth = 175;
 #endif
-
+  viewerTitle = NULL;
+  
   // do Motif-specific initialization and create the window;
   // this also creates the core object
   initWindow(fullScreen);
@@ -315,6 +320,7 @@
   outlineLabelsLength = outlineLabelsSize = 0;
   outlinePaneWidth = 175;
 #endif
+  viewerTitle = NULL;
 
   // do Motif-specific initialization and create the window;
   // this also creates the core object
@@ -400,6 +406,8 @@
   title = app->getTitle() ? app->getTitle()->getCString()
                           : (char *)xpdfAppName;
   XtVaSetValues(win, XmNtitle, title, XmNiconName, title, NULL);
+  setTitle(title,0);
+  setTitle(title,1);
   s = XmStringCreateLocalized("");
   XtVaSetValues(pageNumText, XmNlabelString, s, NULL);
   XmStringFree(s);
@@ -2227,6 +2235,10 @@
 					      about_height,
 					      fg, arm, depth),
 		  NULL);
+    if (viewerTitle) {
+	setTitle(viewerTitle->getCString(),0);
+        setTitle(viewerTitle->getCString(),1);
+    }
   }
 }
 
@@ -2567,6 +2579,85 @@
   XmTextFieldSetString(viewer->pageNumText, buf);
 }
 
+void XPDFViewer::setTitle(char *title, int icon) {
+       char* from;
+       iconv_t cd;
+       char* inptr;
+       size_t insize;
+       char utf8title [4096];
+       char* outptr;
+       size_t outsize;
+       Atom net_wm_name;
+       Atom net_wm_icon_name;
+        Atom utf8_string;
+       
+       net_wm_name = XInternAtom (display, "_NET_WM_NAME", False);
+       net_wm_icon_name = XInternAtom (display, "_NET_WM_ICON_NAME", False);
+       utf8_string = XInternAtom (display, "UTF8_STRING" ,False);
+
+       from  = nl_langinfo (CODESET);
+       cd  = iconv_open ("UTF-8",from);
+       inptr = title;
+       outptr = utf8title;
+       insize = strlen(title);
+       outsize = sizeof (utf8title);
+       memset (&utf8title, 0, sizeof(utf8title));
+       iconv (cd, &inptr, &insize, &outptr, &outsize);
+       iconv_close (cd);
+        Window w;
+
+       if (!win) return;
+        w = XtWindow(win);
+       if (!w) return;
+       
+       if (icon) {
+               XSetWMIconName (
+                       display, w, char_to_xtp (display,utf8title)
+                       );
+               XChangeProperty (
+                       display, w, net_wm_icon_name, utf8_string, 8,
+                       PropModeReplace, (unsigned char *)utf8title,
+                       strlen (utf8title)
+                       );
+       } else {
+               XSetWMName (
+                       display, w, char_to_xtp (display,utf8title)
+                       );
+               XChangeProperty (
+                       display, w, net_wm_name, utf8_string, 8,
+                       PropModeReplace, (unsigned char *)utf8title,
+                       strlen (utf8title)
+                       );
+       }       
+}
+
+XTextProperty* XPDFViewer::char_to_xtp ( Display* dpy, char* s ) {
+       static XTextProperty tp = { 0, 0, 0, 0 };
+       static int free_prop = True;
+       int errCode = 0;
+       char* tl[2];
+       if ( tp.value ) {
+               if ( free_prop ) {
+                       XFree( tp.value );
+               }
+               tp.value = 0;
+               free_prop = True;
+       }
+       tl[0] = s;
+       tl[1] = 0;
+       errCode = XmbTextListToTextProperty (
+               dpy,tl, 1, XStdICCTextStyle, &tp
+       );
+       if ( errCode < 0 ) {
+               tp.value = (unsigned char*)s;
+               tp.encoding = XA_STRING;
+               tp.format = 8;
+               tp.nitems = strlen (s);
+               free_prop = False;
+       }
+    return &tp;
+}
+
 void XPDFViewer::updateCbk(void *data, GooString *fileName,
 			   int pageNum, int numPages, char *linkString) {
   XPDFViewer *viewer = (XPDFViewer *)data;
@@ -2577,9 +2668,14 @@
   if (fileName) {
     if (!(title = viewer->app->getTitle())) {
       title = (new GooString(xpdfAppName))->append(": ")->append(fileName);
+      if (viewer->viewerTitle)
+             delete viewer->viewerTitle;
+      viewer->viewerTitle = title->copy();
     }
     XtVaSetValues(viewer->win, XmNtitle, title->getCString(),
 		  XmNiconName, title->getCString(), NULL);
+    viewer->setTitle(title->getCString(),0);
+    viewer->setTitle(title->getCString(),1);
     if (!viewer->app->getTitle()) {
       delete title;
     }
--- BUILD/xpdf-3.02-poppler/XPDFViewer.h
+++ BUILD/xpdf-3.02-poppler/XPDFViewer.h
@@ -287,6 +287,11 @@
 
   static XPDFViewerCmd cmdTab[];
 
+  //----- setting Window and Icon titles:
+  void setTitle(char *title, int icon);
+  XTextProperty* char_to_xtp ( Display* dpy, char* s );
+  GooString* viewerTitle;
+	  
   XPDFApp *app;
   GBool ok;
 
openSUSE Build Service is sponsored by