Patch for utf-8 window title.
Based on former opensuse patch:
https://build.opensuse.org/package/view_file/DISCONTINUED:openSUSE:11.2/xpdf-poppler/xpdf-poppler-settitle.patch?expand=1
Original one relies upon setlocale(), which isn't in stock xpdf.
To minimize possible impact, I don't import all suse' locale stuff, replacing it by
non-intrusive check for "UTF-8" in environment variable.
Besides of this, the patch uses standard procedure
to set _NET_WM_ICON_NAME(UTF8_STRING) and _NET_WM_NAME(UTF8_STRING) hints
using XmbTextListToTextProperty() with XStdICCTextStyle argument.
Works for me in Jessie and Sid.
sa
diff --git a/xpdf/XPDFViewer.cc b/xpdf/XPDFViewer.cc
index 2de349d..7a70563 100644
--- a/xpdf/XPDFViewer.cc
+++ b/xpdf/XPDFViewer.cc
@@ -258,7 +258,8 @@ XPDFViewer::XPDFViewer(XPDFApp *appA, GString *fileName,
outlineLabelsLength = outlineLabelsSize = 0;
outlinePaneWidth = 175;
#endif
-
+ viewerTitle = NULL;
+
// do Motif-specific initialization and create the window;
// this also creates the core object
initWindow(fullScreen);
@@ -318,6 +319,7 @@ XPDFViewer::XPDFViewer(XPDFApp *appA, PDFDoc *doc, int pageA,
outlineLabelsLength = outlineLabelsSize = 0;
outlinePaneWidth = 175;
#endif
+ viewerTitle = NULL;
// do Motif-specific initialization and create the window;
// this also creates the core object
@@ -409,6 +411,8 @@ void XPDFViewer::clear() {
title = app->getTitle() ? app->getTitle()->getCString()
: (char *)xpdfAppName;
XtVaSetValues(win, XmNtitle, title, XmNiconName, title, NULL);
+ setTitle(title,0);
+ setTitle(title,1);
if (toolBar != None) {
@@ -2303,6 +2307,10 @@ void XPDFViewer::mapWindow() {
about_height,
fg, arm, depth),
NULL);
+ if (viewerTitle) {
+ setTitle(viewerTitle->getCString(),0);
+ setTitle(viewerTitle->getCString(),1);
+ }
}
}
@@ -2635,6 +2643,63 @@ void XPDFViewer::pageNumCbk(Widget widget, XtPointer ptr,
XmTextFieldSetString(viewer->pageNumText, buf);
}
+void XPDFViewer::setTitle(char *title, int icon) {
+ Atom net_wm_name;
+ Atom net_wm_icon_name;
+ Atom utf8_string;
+ char* ev;
+
+ ev = getenv ("LANG");
+ if ((!ev) || (strcasestr (ev, "UTF-8") == NULL))
+ return;
+
+ 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);
+ Window w;
+
+ if (!win) return;
+ w = XtWindow(win);
+ if (!w) return;
+
+ if (icon) {
+ XSetWMIconName (display, w, char_to_xtp (display,title));
+ XChangeProperty (display, w, net_wm_icon_name, utf8_string, 8,
+ PropModeReplace, (unsigned char *)title,
+ strlen (title));
+ } else {
+ XSetWMName (display, w, char_to_xtp (display,title));
+ XChangeProperty (display, w, net_wm_name, utf8_string, 8,
+ PropModeReplace, (unsigned char *)title,
+ strlen (title));
+ }
+}
+
+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, GString *fileName,
int pageNum, int numPages, const char *linkString) {
XPDFViewer *viewer = (XPDFViewer *)data;
@@ -2645,9 +2710,14 @@ void XPDFViewer::updateCbk(void *data, GString *fileName,
if (fileName) {
if (!(title = viewer->app->getTitle())) {
title = (new GString(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;
}
diff --git a/xpdf/XPDFViewer.h b/xpdf/XPDFViewer.h
index 8a345e8..2d3f646 100644
--- a/xpdf/XPDFViewer.h
+++ b/xpdf/XPDFViewer.h
@@ -290,6 +290,11 @@ private:
static XPDFViewerCmd cmdTab[];
+ //----- setting Window and Icon titles:
+ void setTitle(char *title, int icon);
+ XTextProperty* char_to_xtp ( Display* dpy, char* s );
+ GString* viewerTitle;
+
XPDFApp *app;
GBool ok;