;;; 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 . ;;; 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