From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thibault Polge Newsgroups: gmane.emacs.bugs Subject: bug#58945: 29.0.50; Setting frame name in pgtk Emacs is asynchronous Date: Tue, 01 Nov 2022 15:58:22 +0100 Message-ID: <87pme6oh69.fsf@thb.lt> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25122"; mail-complaints-to="usenet@ciao.gmane.io" To: 58945@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 01 18:30:30 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1opv5p-0006L1-GD for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 01 Nov 2022 18:30:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opsjI-0007Kq-NP; Tue, 01 Nov 2022 10:59:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opsjG-0007KX-9q for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 10:59:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1opsjG-0004WU-2O for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 10:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1opsjF-0004fe-Lx for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 10:59:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Thibault Polge Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Nov 2022 14:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58945 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166731473217938 (code B ref -1); Tue, 01 Nov 2022 14:59:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Nov 2022 14:58:52 +0000 Original-Received: from localhost ([127.0.0.1]:43979 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opsj6-0004fG-Gh for submit@debbugs.gnu.org; Tue, 01 Nov 2022 10:58:52 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:44856) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opsj4-0004f7-DW for submit@debbugs.gnu.org; Tue, 01 Nov 2022 10:58:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opsj4-0007K4-7U for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 10:58:50 -0400 Original-Received: from 4.mo581.mail-out.ovh.net ([178.32.122.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opsiu-0004D4-78 for bug-gnu-emacs@gnu.org; Tue, 01 Nov 2022 10:58:50 -0400 Original-Received: from player788.ha.ovh.net (unknown [10.108.1.93]) by mo581.mail-out.ovh.net (Postfix) with ESMTP id BD55324292 for ; Tue, 1 Nov 2022 14:58:26 +0000 (UTC) Original-Received: from thb.lt (lfbn-idf3-1-593-4.w86-252.abo.wanadoo.fr [86.252.170.4]) (Authenticated sender: thibault@thb.lt) by player788.ha.ovh.net (Postfix) with ESMTPSA id 386CE30453461 for ; Tue, 1 Nov 2022 14:58:26 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-97G0029975ace2-c7e1-4cc9-8a8d-9d87a6a0baeb, 23475F9B9015D82EF06BF9B783FA02D60958033E) smtp.auth=thibault@thb.lt X-OVh-ClientIp: 86.252.170.4 X-Ovh-Tracer-Id: 3752061440978305956 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvgedrudehgdejudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvufffkfggtgesmhdtreertddttdenucfhrhhomhepvfhhihgsrghulhhtucfrohhlghgvuceothhhihgsrghulhhtsehthhgsrdhltheqnecuggftrfgrthhtvghrnhepieehheeikeejieejhfeffeethfdtteevvdevfeegvdeiieefleegteegtdegvddunecukfhppeduvdejrddtrddtrddupdekiedrvdehvddrudejtddrgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehthhhisggruhhlthesthhhsgdrlhhtqedpnhgspghrtghpthhtohepuddprhgtphhtthhopegsuhhgqdhgnhhuqdgvmhgrtghssehgnhhurdhorhhgpdfovfetjfhoshhtpehmohehkedupdhmohguvgepshhmthhpohhuth Received-SPF: pass client-ip=178.32.122.254; envelope-from=thibault@thb.lt; helo=4.mo581.mail-out.ovh.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246793 Archived-At: --=-=-= Content-Type: text/plain In pgtk Emacs (built from a very recent git HEAD), running under the Sway window manager, setting a frame name like this: (set-frame-parameter (selected-frame) 'name "Some new name") (redisplay t) Doesn't immediately take effect. The example program below demonstrates this by triggering a race condition: it renames all frames, then immediately requests the state of the Sway window manager, and renames them back. Repeatedly eval'ing the final sexp randomly returns either the original or the renamed frame names. (When testing with a few frames, it never returned a mix of original or renamed names --- it's 100% one or the other) This is an issue because frame names is the only way to associate Emacs frames with Sway identifiers (or any wayland wm) on pgtk Emacs). MWE code follows. Best regards, Thibault --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=mwe.el Content-Transfer-Encoding: quoted-printable (require 'dash) (require 'json) (defun uniquify-frame-names () "Give all frames a unique numeric ID." (progn (mapc (lambda (it) ;; Preserve already saved names. (unless (frame-parameter it '--saved-name) ;; Save the frame name (set-frame-parameter it '--saved-name (frame-parameter it 'name))) (set-frame-parameter it 'name (frame-parameter it 'window-id))) (frame-list)))) (defun restore-frame-names () "Restore frame names from their saved value." (mapc (lambda (it) (when (frame-parameter it '--saved-name) (set-frame-parameter it 'name (let ((name (frame-parameter it '--saved-name))) ;; We can't restore names of the form ;; F, see frame.c:3080: error ;; ("Frame names of the form F are ;; usurped by Emacs"); (unless (string-match "^F[[:digit:]]*$" name) name))) (set-frame-parameter it '--saved-name nil))) (frame-list))) (defun collect-emacs-frames-from-sway-tree (tree) "Return frames belonging to this Emacs in parsed Sway tree TREE." (let ((next-tree (gethash "nodes" tree))) (if (and (zerop (length next-tree)) (not (string=3D "workspace" (gethash "type" tree))) (eq (gethash "pid" tree) (emacs-pid))) tree ; Collect (-flatten ; Or recurse (mapcar (lambda (t2) (collect-emacs-frames-from-sway-tree t2)) next-tree))))) ;; ! Eval this again and again=20 (prog2 ;; Rename all frames (progn (uniquify-frame-names) (redisplay t)) ;; Get list of containers from sway, and find our frames by pid. (mapcar (lambda (it) (gethash "name" it)) (collect-emacs-frames-from-sway-tree (with-temp-buffer (call-process "swaymsg" nil (current-buffer) nil "-t" "get_tree") (goto-char (point-min)) (json-parse-buffer :null-object nil :false-object nil)))) ;; Rename back frames. (restore-frame-names)) --=-=-=--