From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.devel Subject: Re: xterm-mouse-mode gives incorrect posn-object-x-y with display space Date: Fri, 25 Nov 2022 10:15:37 -0500 Message-ID: References: <835yf4w6a7.fsf@gnu.org> <5BBC7E49-41C3-4693-95F6-26E8EAC7F7A4@gmail.com> <83tu2nv6rs.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33385"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 25 16:16:22 2022 Return-path: Envelope-to: ged-emacs-devel@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 1oyaRC-0008V5-AM for ged-emacs-devel@m.gmane-mx.org; Fri, 25 Nov 2022 16:16:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyaQb-0003gX-UL; Fri, 25 Nov 2022 10:15:45 -0500 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 1oyaQZ-0003ds-PC for emacs-devel@gnu.org; Fri, 25 Nov 2022 10:15:43 -0500 Original-Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oyaQX-0002pq-S3; Fri, 25 Nov 2022 10:15:43 -0500 Original-Received: by mail-io1-xd30.google.com with SMTP id z3so3240456iof.3; Fri, 25 Nov 2022 07:15:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sanLLazjv9qr1E/1nGlI7WPO0pCXy5KM5rmo2AFwWmc=; b=IXl8vp7tQSEqS1FA8g3S6k8n+KAhZWiskduHg23+lJ0XLcubAopTUfzxOCDB+3Ac8M ua13RfMv9/WG/cXwSMBd1Sf5+2ZdjpXRs3F7uS5FrY2a0F6MMOC7ingD4ykYJrjv4tjm 3JZcGy2Gc7KToY5P4AeQCBSoN1Sodpx8UfvFVhtr4c4krnObrTwFQ6GjwZIsZsg7Gw+W GQjxaZ/+508d4uIgMzlyJAgnYpEtpEm7qNJ7AubdyiO+9MAXX9y/6H58jXrbWZPvXA71 suzK2Nkl4jzvSnrD1gnoc2ToeRUfSg4X14VPgKaKpdegOczWS47ciXbURJ2lUqIltoUG tVJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sanLLazjv9qr1E/1nGlI7WPO0pCXy5KM5rmo2AFwWmc=; b=1JzXd0O6afZMBgcRpx4c7NoGZocSPktp4T8zywvKy9Y3zp0b+pKKuwc1EPIkdceXQK G3wUtSfRY6GiBJtD2wl+tsEKBEPHXPLQGiVSKNxMufTppBBLPKwa1dRYPT3nRPIJuihb yP8Yf0AH9IQVbHG8pf6Bvl0WdvEs25dlIgGpu8VJS2yyAqjPEw/xXXjHJz8ZxOyq4aaQ LLmWLhG+vsA4JhgvHx7XGP2vt2myzI0XcGkn1Ki0v3dp+i5COv7ICXNK881bjauVsaST fu+JWJAdQugPdNLZsmh7O4IlWL9NPVo1aiD+G3YHNsmcnjpyw2Z+3w2c5oF7spwr3RTK NNxA== X-Gm-Message-State: ANoB5pmLMXMmu9OosQnJlEU4yqX6OGtDivt8VUbBNf9cB4riBYY3BN/W 7MUjVoEZ6GeTIFlAEC5aPH/X3TzA+tY= X-Google-Smtp-Source: AA0mqf6cAyRUaTCLo5KzAXDedjb46scfjdWGmwCz4ERey1cDzPuj2FN1HsPqn73KtRk4ejnHl4oy7g== X-Received: by 2002:a05:6638:c1:b0:376:22d5:a030 with SMTP id w1-20020a05663800c100b0037622d5a030mr9040806jao.17.1669389339918; Fri, 25 Nov 2022 07:15:39 -0800 (PST) Original-Received: from smtpclient.apple (cm-24-53-184-207.buckeyecom.net. [24.53.184.207]) by smtp.gmail.com with ESMTPSA id m16-20020a0566022e9000b006deea01ff39sm1497875iow.22.2022.11.25.07.15.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Nov 2022 07:15:39 -0800 (PST) In-Reply-To: <83tu2nv6rs.fsf@gnu.org> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::d30; envelope-from=jdtsmith@gmail.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300488 Archived-At: > On Nov 25, 2022, at 2:21 AM, Eli Zaretskii wrote: >=20 >> From: JD Smith >> Date: Thu, 24 Nov 2022 16:42:29 -0500 >> Cc: emacs-devel@gnu.org >>=20 >> Thanks. The documentation on posn-object-* provides no guidance that = a =E2=80=9Cstring object=E2=80=9D would not include a >> stretched string with specified space. So it was not at all = surprising to me that it worked "as expected" in the >> GUI. In further support of this impression (leaving aside specified = space), posn-object-x-y works perfectly >> well on normal width characters in the buffer, providing pixel level = information on where *within the >> character* you clicked. In fact I cannot think what "pixel-based x = and y coordinates relative to the upper left >> corner=E2=80=9D would mean other than this for a "string object". = Surely that is not an accident of the >> implementation! >=20 > Yes, but on TTY frames the DX/DY _within_ the character glyph are = always > zero, because each character is considered to be exactly one "pixel". = And > if I tell you that stretches of whitespace produced by 'space' display = specs > are implemented on TTY as sequences of SPC characters (of course, what > else?), then I think you will understand why the DX/DY values, defined = in > the ELisp manual as "the coordinates relative to the top left corner = of the > character glyph clicked on", on a TTY are always zero: wherever the = click > is, it is always on a glyph of some SPC character from those that = represent > the stretch of whitespace. Thanks for these details. This I had indeed understood; with char = units, you can=E2=80=99t and won't get any pixel offsets within a single = char glyph. Since for the TTY, Emacs implements a specified space under = the hood as a =E2=80=9Cseries of spaces=E2=80=9D, the natural thing for = consistency with the GUI would be for posn-object-x-y to report click = position offsets (in integer character units, naturally) within that = stretched space. It sounds like this may be challenging to implement = internally, but it would be the most consistent. It must be possible, = since Emacs 1) knows it drew a specified space as a series of space = chars in the TTY, and 2) knows (or could know) where the click occurred = within that group of space chars it drew. To summarize, the fact that in the TTY a stretched space is implemented = as a collection of space chars, and on GUI, some other type of = pixel-precise graphical element is IMO just an implementation detail. = What if TTY=E2=80=99s of the future allow drawing small graphical = elements at pixel precision? How is the user of posn-object-* to know = which of the two different and incompatible result flavors they will = get? >> Is there a reliable way to determine where (in pixels [1]) the mouse = was clicked relative to a string displayed >> with specified space, which works equally in the GUI and TTYs? Keep = in mind that the string may not be at >> a fixed column, but at an arbitrary pixel offset from the window (due = to prior specified space, variable width >> fonts, etc.). =20 >=20 > Please tell more about your use case. I don't think I understand what = you > mean by "string displayed with specified space=E2=80=9D; This is how I implement mlscroll, a mode line scroll bar we=E2=80=99ve = discussed here before. The basic design is 3 specified spaces in a row = , usually right-aligned in the mode line. Together these 3 (varying = width) spaces indicate the number of lines: i) above ii) showing, and = iii) after the window. Just like a =E2=80=9Creal=E2=80=9D scrollbar, = the user can interact with it by clicking/dragging/etc. When clicking = on the bar, the precise relative click position determines what lines = are scrolled into view (again, just like a real scrollbar). = Surprisingly it looks pretty good on TTY without any special casing, = though obviously with char- instead of pixel-granularity. But this = happy consistency breaks down with xterm-mouse-mode, since clicks on the = modeline scrollbar are not reportable as positions w.r.t. the clicked = element, i.e. since posn-object-x-y always reports 0 on TTY. =20 > If I have to guess what you want, then my suggestion would be to use > something like this: >=20 > (let* ((event-posn (posn-point (event-start ev))) > (click-x-y (posn-x-y (event-start ev))) > (obj-x-y (posn-x-y (posn-at-point event-posn)))) > (cons (- (car click-x-y) (car obj-x-y)) > (- (cdr click-x-y) (cdr obj-x-y)))) >=20 > IOW, don't trust DX/DY, but calculate the offsets "by hand". Thanks for your good suggestion; this would indeed work as desired in = the buffer, since posn-at-point does seem to =E2=80=9Cknow=E2=80=9D = it=E2=80=99s in a specified space in both GUI and TTY (which makes me = think posn-object-x-y should also be able to know this). Unfortunately posn-point returns nil for posn-area =3D mode-line, so = this does not solve the problem. Is there any other way you know to = determine the starting char position of the _group of spaces_ that TTY = Emacs translates a specified space into, in the mode line? Calculating = the char-start of the scrollbar myself will be challenging given dynamic = modeline elements and the possibility for the user to place the = scrollbar anywhere they want (i.e. not just right-aligned).=