1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
| | ;;; touch-screen.el --- Touchscreen support for GNU Emacs. -*- lexical-binding: t -*-
;; Copyright (C) 2020 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package provides touch-screen support for GNU Emacs on GTK 4 terminals.
;; This relies on several GTK 4-specific event handling changes, and is unlikely
;; to work well on other platforms.
;;; Code:
(unless (and (or (string-prefix-p "3.98" gtk-version-string)
(string-prefix-p "4." gtk-version-string)))
(error "Trying to load touch-screen.el on an incompatible terminal"))
(require 'widget)
(defvar touch-screen--idle-timer nil
"The timer that will be used for action popovers.")
(defun touch-screen-pop-up-actions-frame ()
"Display the selection items popover."
(interactive)
(pgtk-show-selection-options (selected-frame)))
(define-minor-mode touch-screen-mode
"A mode for touchscreen device that displays
several graphical elements suitable for use on touchscreens."
:global t
:lighter nil)
(defun touch-screen--after-mark-set ()
"Internal function for `touch-screen-after-mark-set'."
(when (and pgtk-last-event-from-touchscreen
touch-screen-mode
(region-active-p)
(window-system)
(> (abs (- (mark) (point))) 5))
(touch-screen-pop-up-actions-frame)))
(defun touch-screen-after-mark-set ()
"This function will be run after the mark is set.
It will display the pop-up frame if `pgtk-last-event-from-touchscreen'
is non-nil."
(when (window-system)
(when touch-screen--idle-timer
(cancel-timer touch-screen--idle-timer))
(setq touch-screen--idle-timer
(run-with-idle-timer 1 nil #'touch-screen--after-mark-set))))
(defun touch-screen--safe-kill ()
"Kill the region, without raising errors if it is not possible."
(when (not (and buffer-read-only
(not inhibit-read-only)
(not (get-text-property (point) 'inhibit-read-only))))
(unwind-protect
(kill-region (mark) (point))
nil)))
(add-hook 'activate-mark-hook #'touch-screen-after-mark-set)
(add-hook 'post-command-hook #'touch-screen-after-mark-set)
(provide 'touch-screen)
;;; touch-screen.el ends here
|