gv/gv-3.6.3-settitle.patch

128 lines
3.2 KiB
Diff

--- src/callbacks.c
+++ src/callbacks.c 2004-04-30 22:59:01.000000000 +0200
@@ -62,6 +62,11 @@
#include <sys/stat.h>
#include <unistd.h>
+#include <locale.h>
+#include <langinfo.h>
+#include <iconv.h>
+#include INC_X11(Xatom.h)
+
#include "types.h"
#include "actions.h"
#include "callbacks.h"
@@ -95,6 +100,82 @@ static char* open_directory = NULL;
/* cb_showTitle */
/*############################################################*/
+void setTitle ( Display* dpy, Window w, char* title, int icon);
+XTextProperty* char_to_xtp ( Display* dpy, char* s );
+
+void setTitle ( Display* dpy, Window w, 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 (dpy, "_NET_WM_NAME", False);
+ net_wm_icon_name = XInternAtom (dpy, "_NET_WM_ICON_NAME", False);
+ utf8_string = XInternAtom (dpy, "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);
+
+ if (icon) {
+ XSetWMIconName (
+ dpy, w, char_to_xtp (dpy,utf8title)
+ );
+ XChangeProperty (
+ dpy, w, net_wm_icon_name, utf8_string, 8,
+ PropModeReplace, (unsigned char *)utf8title,
+ strlen (utf8title)
+ );
+ } else {
+ XSetWMName (
+ dpy, w, char_to_xtp (dpy,utf8title)
+ );
+ XChangeProperty (
+ dpy, w, net_wm_name, utf8_string, 8,
+ PropModeReplace, (unsigned char *)utf8title,
+ strlen (utf8title)
+ );
+ }
+}
+
+XTextProperty* 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
cb_showTitle(w, client_data, call_data)
Widget w;
@@ -124,6 +205,8 @@ cb_showTitle(w, client_data, call_data)
} else {
t = s = GV_XtNewString(versionIdentification[0]);
}
+ if (w && XtWindow(w)) setTitle(gv_display, XtWindow(w), s, 0);
+ if (w && XtWindow(w)) setTitle(gv_display, XtWindow(w), t, 1);
n=0;
XtSetArg(args[n], XtNtitle, s); n++;
XtSetArg(args[n], XtNiconName, t); n++;
--- src/main.c
+++ src/main.c 2004-04-30 22:50:21.000000000 +0200
@@ -1226,6 +1226,7 @@ int main(argc, argv)
INFMESSAGE(mapping toplevel)
XtMapWidget(toplevel);
+ cb_showTitle(toplevel, NULL, NULL);
}
INFMESSAGE(waiting for events now)
--- src/misc.c
+++ src/misc.c 2008-03-27 17:16:44.877346759 +0100
@@ -932,7 +932,7 @@ setup_ghostview()
gv_pagemedia = m;
}
}
- cb_showTitle(NULL,NULL,NULL);
+ cb_showTitle(toplevel,NULL,NULL);
if (show_date) {
if (doc && doc->date) {