Re: Re: [dev] [st][patch] more work on the XEmbed embedder

2024-02-04 Thread Robin Haberkorn
 == FocusIn) {
+		XRaiseWindow(xw.dpy, embed);
+		XSetInputFocus(xw.dpy, embed, RevertToParent, CurrentTime);
+		sendxembed(XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT, 0, 0);
+		sendxembed(XEMBED_WINDOW_ACTIVATE, 0, 0, 0);
+	}
+
 	if (e->mode == NotifyGrab)
 		return;
 
@@ -1905,9 +1977,17 @@ cmessage(XEvent *e)
 void
 resize(XEvent *e)
 {
+	XWindowChanges wc;
+
 	if (e->xconfigure.width == win.w && e->xconfigure.height == win.h)
 		return;
 
+	if (embed) {
+		wc.width = e->xconfigure.width;
+		wc.height = e->xconfigure.height;
+		XConfigureWindow(xw.dpy, embed, CWWidth | CWHeight, );
+	}
+
 	cresize(e->xconfigure.width, e->xconfigure.height);
 }
 
-- 
2.43.0

>From 4de1ba2a851515da01000f8ed7406d4669bdecc3 Mon Sep 17 00:00:00 2001
From: Robin Haberkorn 
Date: Thu, 1 Feb 2024 17:11:48 +0300
Subject: [PATCH 2/3] Embedder: This respects the embedded window's name/title

Imports gettextprop() from tabbed.c.
---
 x.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/x.c b/x.c
index aaa8139..6b3a8e1 100644
--- a/x.c
+++ b/x.c
@@ -192,6 +192,8 @@ static int match(uint, uint);
 static void createnotify(XEvent *e);
 static void destroynotify(XEvent *e);
 static void sendxembed(long msg, long detail, long d1, long d2);
+static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
+static void updatetitle(Window win);
 
 static void run(void);
 static void usage(void);
@@ -524,6 +526,9 @@ propnotify(XEvent *e)
 			(xpev->atom == XA_PRIMARY ||
 			 xpev->atom == clipboard)) {
 		selnotify(e);
+	} else if (xpev->state != PropertyDelete && xpev->atom == XA_WM_NAME &&
+	   embed == xpev->window) {
+		updatetitle(embed);
 	}
 }
 
@@ -767,6 +772,8 @@ createnotify(XEvent *e)
 	XReparentWindow(xw.dpy, embed, xw.win, 0, 0);
 	XSelectInput(xw.dpy, embed, PropertyChangeMask | StructureNotifyMask | EnterWindowMask);
 
+	updatetitle(embed);
+
 	XMapWindow(xw.dpy, embed);
 	sendxembed(XEMBED_EMBEDDED_NOTIFY, 0, xw.win, 0);
 
@@ -803,6 +810,44 @@ sendxembed(long msg, long detail, long d1, long d2)
 	XSendEvent(xw.dpy, embed, False, NoEventMask, );
 }
 
+Bool
+gettextprop(Window w, Atom atom, char *text, unsigned int size)
+{
+	char **list = NULL;
+	int n;
+	XTextProperty name;
+
+	if (!text || size == 0)
+		return False;
+
+	text[0] = '\0';
+	XGetTextProperty(xw.dpy, w, , atom);
+	if (!name.nitems)
+		return False;
+
+	if (name.encoding == XA_STRING) {
+		strncpy(text, (char *)name.value, size - 1);
+	} else if (XmbTextPropertyToTextList(xw.dpy, , , ) >= Success
+	   && n > 0 && *list) {
+		strncpy(text, *list, size - 1);
+		XFreeStringList(list);
+	}
+	text[size - 1] = '\0';
+	XFree(name.value);
+
+	return True;
+}
+
+void
+updatetitle(Window win)
+{
+	char name[256];
+
+	if (!gettextprop(win, xw.netwmname, name, sizeof(name)))
+		gettextprop(win, XA_WM_NAME, name, sizeof(name));
+	xsettitle(name);
+}
+
 void
 xresize(int col, int row)
 {
-- 
2.43.0

>From 73028d36e877c3c918ba96ffc95a3cc2a1b710b2 Mon Sep 17 00:00:00 2001
From: Robin Haberkorn 
Date: Sat, 3 Feb 2024 03:36:47 +0300
Subject: [PATCH 3/3] inherit window icon from embedded (Xembed) application

* This is largely taken from tabbed's "icon" patch (cf. xseticon()):
  https://tools.suckless.org/tabbed/patches/icon/
* I found that some applications that show their icon flawlessly in the WM
  won't work (neither in st, nor in tabbed).
  This was the case with SciTECO, but it could be resolved
  by reordering some statements.
* Once the embedded application terminates, we try to remove the icon again.
  `xprop` confirms that this worked.
  Unfortunately, Awesome WM will continue to show the old icon, which
  is probably an Awesome WM bug.
  Perhaps we should therefore apply this patch on top of netwmicon (FIXME):
  https://st.suckless.org/patches/netwmicon/
---
 x.c | 49 +
 1 file changed, 49 insertions(+)

diff --git a/x.c b/x.c
index 6b3a8e1..66dccc4 100644
--- a/x.c
+++ b/x.c
@@ -194,6 +194,7 @@ static void destroynotify(XEvent *e);
 static void sendxembed(long msg, long detail, long d1, long d2);
 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
 static void updatetitle(Window win);
+static void updateicon(Window win);
 
 static void run(void);
 static void usage(void);
@@ -520,6 +521,7 @@ propnotify(XEvent *e)
 {
 	XPropertyEvent *xpev;
 	Atom clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
+	Atom wmicon = XInternAtom(xw.dpy, "_NET_WM_ICON", 0);
 
 	xpev = >xproperty;
 	if (xpev->state == PropertyNewValue &&
@@ -529,6 +531,9 @@ propnotify(XEvent *e)
 	} else if (xpev->state != PropertyDelete && xpev->atom == XA_WM_NAME &&
 	   embed == xpev->window) {
 		updatetitle(embed);
+	} else if ((xpev->atom == wmicon || xpev->state == PropertyNewValue && xpev-&

Re: [dev] [st][patch] more work on the XEmbed embedder

2024-02-04 Thread Robin Haberkorn
04.02.24 12:52, Hiltjo Posthuma пишет:
> Hi,
> 
> If you want to contribute to upstream you need to rebase the patches on the
> master version of st.
> 
> Then you send the patches (git-format-patch) to the mailinglist.
> Okay. But first of all, there are remaining problems. I would like to resolve
the freeze-issue first. Secondly, this would be the wrong mailing list.
Thirdly, I doubt that the maintainers would want to merge this into mainline.

If you want to to try the patches in their current form, just build my version
or cherry-pick the commits into your own st-patch-branch.
Or does anybody insist I send them around in patch files?



[dev] [st][patch] more work on the XEmbed embedder

2024-02-03 Thread Robin Haberkorn
Hello!

I picked up the patch from Jochen Sprickerhof 
that was posted on hack...@suckless.org a few years ago, allowing you to
embed applications into st via Xembed. So this is the _host_ side of
Xembed, very similar to what tabbed does. The thing is, you do not always
want to open apps in new tabs - I personally do not use tabbed
at all - but you just want it to cover your terminal window, so it behaves
more like a fullscreen terminal application and does not spawn a new X11
window that may ruin your tiling layout etc.

Check out to the last 3 patches on this branch:
https://github.com/rhaberkorn/st/commits/patches/
(The others are really just patches I personally use for customization.)

This has been tested with SciTECO (https://github.com/rhaberkorn/sciteco),
nsxiv and mpv (--wid).
Zathura unfortunately does not work flawlessly. It does not refresh its
window once embedded. And neither does Zathura work with tabbed.

Also, st windows tend to freeze after resizing them a bit (but only while
a client is embedded).

I am not very experienced in Xlib programming, so perhaps somebody else
could have a look. Somebody who knows tabbed better than I do.

Another issue is that once an embedded app terminates, I try to remove
the icon from the st window. xprop confirms that this works.
But at least Awesome WM does not respect this change and continues
to display the old icon.
I suspect this is an Awesome WM bug.
Perhaps somebody could test with another WM.

I like this feature so much, I also looked into whether it would be
possible to somehow hack Gtk (e.g. using LD_PRELOAD) so you can
embed most Gtk applications - after all they provide GtkPlug and it
also derives from GtkWindow. Unfortunately, this would not be trivial.
It might be easier to patch Gtk itself.

All of this should perhaps eventually be part of the Wiki once
we fixed the remaining problems.

Best regards,
Robin