├── LICENSE
├── Makefile
├── README.md
├── extension.js
├── metadata.json
├── pref-im-alt2.png
├── pref-im.png
├── pref-op.png
├── pref-tp.png
├── prefs.js
├── schemas
└── org.gnome.shell.extensions.inputmethod-shortcuts.gschema.xml
└── test-keys
├── LICENSE
├── Makefile
├── README.md
├── extension.js
├── metadata.json
├── prefs.js
└── schemas
└── org.gnome.shell.extensions.test-keys.gschema.xml
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # release guide
2 | # * run "make zip"
3 | # * open browser: https://extensions.gnome.org/upload/
4 | # * upload zip file
5 |
6 | UUID = inputmethod-shortcuts@osamu.debian.org
7 | EXTENSIONS_PATH = ~/.local/share/gnome-shell/extensions
8 | INSTALL_PATH = $(EXTENSIONS_PATH)/$(UUID)
9 | FILES = README.md \
10 | LICENSE \
11 | extension.js \
12 | metadata.json \
13 | prefs.js \
14 | schemas/
15 |
16 | .PHONY: all build zip repo install clean
17 | all: build
18 |
19 | build:
20 | glib-compile-schemas --strict --targetdir=schemas/ schemas
21 |
22 | zip: build
23 | rm -f $(UUID).zip
24 | zip -r $(UUID).zip $(FILES)
25 |
26 | install: build
27 | rm -rf $(INSTALL_PATH)
28 | mkdir -p $(INSTALL_PATH)
29 | cp -r $(FILES) $(INSTALL_PATH)/
30 |
31 | uninstall: build
32 | rm -rf $(INSTALL_PATH)
33 |
34 | # use_markup is not supported GNOME 40-42
35 | backport:
36 | sed -i -E -e 's/, *use_markup *: *true//' -e 's/<\/?i>//g' -e 's/<\/?b>//g' -e 's///g' -e 's/<\/a>//g' prefs.js
37 | sed -i -E -e 's/^.*shell-version.*$$/ "shell-version": [ "40", "41", "42" ],/' metadata.json
38 |
39 | clean:
40 | rm -f $(UUID).zip
41 | rm -f schemas/gschemas.compiled
42 | # vim: set ts=8:
43 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Quick switching of input method and touchpad
2 | ============================================
3 |
4 | This is a GNOME shell extension which allows us to set up custom keyboard
5 | shortcuts for:
6 | - quick switching of input method (first 10 available ones) and
7 | - quick switching of touchpad.
8 |
9 | This can make keyboard input experiences quick (pop-up-less), non-interfering,
10 | stateless and deterministic while keeping the original behavior available (if
11 | you wish). This shortcut can automatically sets xkb to the first one before
12 | entering ibus input method. (This default setting fixes issues of ibus with
13 | non-latin inputs such as xkb=ru etc. This is a configurable feature.)
14 |
15 | I found "Disable While Typing" (in GNOME "Tweaks" -> "Keyboard & Mouse" ->
16 | "Touchpad") is not perfect solution. Keyboard shortcuts can ensure you to avoid
17 | touchpad interferences with minimal user efforts.
18 |
19 | If you happen to have more than 10 input methods, they can be used through the
20 | normal center selection panel if you don't intentionally disable pertinent
21 | shortcuts. If you intentionally disable such shortcuts, these convenient
22 | keys can be used by this extension.
23 |
24 | Due to the difference of support for `use_markup`, I make 2 packages depending
25 | on target GNOME versions: one for GNOME 40-42, another for GNOME 43 and 44.
26 |
27 | Due to the
28 | [major change in GNOME 45](https://blogs.gnome.org/shell-dev/2023/09/02/extensions-in-gnome-45/),
29 | this source code was ported to standard JavaScript modules (ESM) by Álan
30 | Crístoffer to support GNOME 45 and after.
31 |
32 | ## Usage
33 |
34 | First, you must set up all your input methods from GNOME GUI:
35 |
36 | - `Settings` -> `Keyboard` -> `Input Sources` etc.
37 |
38 | Then install this GNOME extensions using your browser from the GNOME extensions site:
39 |
40 | - https://extensions.gnome.org/extension/6066/shortcuts-to-activate-input-methods/
41 |
42 | Afterwards, restart the GNOME shell by log-out and log-in from GUI. You can
43 | also use CLI `killall gnome-shell` to log out. This is essential process to
44 | get GNOME shell extensions to function as expected.
45 |
46 | Then, enable this extension from GUI, e.g., `gnome-extensions-app`
47 | (**Extensions**) in GNOME 43 or later; or from **GNOME Tweaks** menu in older
48 | GNOME. You must set up each shortcut first to use this extension.
49 |
50 | The pre-exiting shortcut key can't be reused. You must disable their usage
51 | first, elsewhere.
52 |
53 | If you change installed input methods, you must restart this extension.
54 |
55 | ### Input Method Shortcuts (example screenshot)
56 |
57 | 
58 |
59 | Here, I disabled `Space` and `Space` usages in "Settings"
60 | -> "Keyboard" -> "Keyboard shortcuts" -> "Typing" before setting up as above.
61 |
62 | Please note that, if an ibus can offer its internal shortcuts to activate input
63 | method engine (IME) and to deactivate IME by using direct input mode just with
64 | xkb for latin character set, switching between IME and direct input mode within
65 | ibus is quicker than using Desktop based input method switching functionality
66 | handled by this extension.
67 |
68 | ### Touchpad Shortcuts (example screenshot)
69 |
70 | 
71 |
72 | Please note that you don't need to set all shortcut bindings.
73 |
74 | ### Operation Preference (example screenshot)
75 |
76 | 
77 |
78 | ### Ideas for other shortcut keys
79 |
80 | Here are other ideas for shortcut keys.
81 |
82 | - `u` (**u** for US)
83 | - `i` (**i** for International)
84 | - `j` (**j** for Japanese)
85 | - `k` (**k** for Korean)
86 | - `c` (**c** for Chinese)
87 | - `z` (**z** for Chinese=zh)
88 |
89 | Even unusual key combos of Modifierkeys can be used as shortcuts.
90 |
91 | - `Shift_R` -- Press `Shift_L` then press `Shift_R`
92 | - `Shift_L` -- Press `Shift_R` then press `Shift_L`
93 | - `Caps_Lock`
94 | - `Shift_R`
95 | - `Shift_L`
96 | - `Caps_Lock`
97 | - `Shift_R`
98 | - `Shift_L`
99 | - `Caps_Lock`
100 | - `Shift_R`
101 | - `Shift_L`
102 | - `Caps_Lock`
103 | ...
104 |
105 | If some other program already binds a key combination for shortcut, that key
106 | combination can't be registered. (Using `Alt_R` key as the 2nd key part for
107 | these combos of Modifierkeys is not a good idea due to many complications.)
108 |
109 | For example, I ended up keeping original input method switching with
110 | `space` by using:
111 |
112 | Some keyboards doesn't support odd key combinations of Modification keys at the
113 | hardware keyboard level. In such case, avoid using such combinations.
114 |
115 | 
116 |
117 | Here, I use "US, intl., with AltGr dead keys" (`us+altgr-intl`) to enter
118 | accented latin characters. This is less stressful method than "US, intl., with
119 | dead keys" which functions like the default Windows international environment.
120 |
121 | ### Ways to reorder input methods
122 |
123 | If you have multiple xkb methods, you may need to reorder input methods so the
124 | first xkb method may be set as the preferred one for ibus input methods via
125 | quick CLI.
126 |
127 | ```sh
128 | $ gsettings get org.gnome.desktop.input-sources sources
129 | [('xkb', 'ru'), ('xkb', 'us'), ('ibus', 'anthy'), ('ibus', 'mozc-jp'), ('xkb', 'us+altgr-intl')]
130 | $ gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'us'), ('ibus', 'mozc-jp'), ('xkb', 'us+altgr-intl'), ('ibus', 'anthy'), ('xkb', 'ru')]"
131 | $ gsettings get org.gnome.desktop.input-sources sources
132 | [('xkb', 'us'), ('ibus', 'mozc-jp'), ('xkb', 'us+altgr-intl'), ('ibus', 'anthy'), ('xkb', 'ru')]
133 | ```
134 |
135 | ## Development
136 |
137 | The latest development version is available at:
138 |
139 | * [GITHUB repository](https://github.com/osamuaoki/inputmethod-shortcuts)
140 | * branch `main`: support for GNOME 45 and after (version 23, 24, ...)
141 | * branch `backport43`: support for GNOME 43 - 44 (version 21)
142 | * branch `backport`: support for GNOME 40 - 42 (version 20)
143 | GNOME site:
144 | * [GNOME extension download](https://extensions.gnome.org/extension/6066/shortcuts-to-activate-input-methods/)
145 | * [GNOME extension upload](https://extensions.gnome.org/upload)
146 |
147 | You can install this extension for testing locally by:
148 |
149 | ```sh
150 | $ git clone https://github.com/osamuaoki/inputmethod-shortcuts
151 | $ cd inputmethod-shortcuts
152 | $ make install
153 | ```
154 |
155 | This will install files into your `
156 | ~/.local/share/gnome-shell/extensions/inputmethod-shortcuts@osamu.debian.org`
157 | directory without accessing the GNOME extension web site.
158 |
159 | Afterwards, restart the GNOME shell by log-out and log-in from GUI. You can
160 | also use CLI `killall gnome-shell` to log out. This is essential process to
161 | get GNOME shell extension to function as expected.
162 |
163 | This code was started to be based on similar GNOME shell extensions and
164 | previous method to switch input methods:
165 | - https://github.com/matthijskooijman/gnome-shell-more-keyboard-shortcuts
166 | - https://gitlab.com/paddatrapper/shortcuts-gnome-extension (IGNORE_AUTOREPEAT)
167 | - https://www.mail-archive.com/gnome-shell-list@gnome.org/msg08988.html (previous method)
168 |
169 | Resulting extension code was useful and functional for me but it had many rough
170 | edges since this was my first javascript program without even reading its
171 | references. Prior to getting this accepted by GNOME extension site,
172 | **JustPerfection** guided me to fix such rough edges by making me to rewrite
173 | practically the whole code. Then, I rewrote whole code using ES6 style and
174 | added touchpad controls.
175 |
176 | For touchpad, I wanted to have 2 independent shortcuts to turn it on and off.
177 | So I added them to this extension. Since making toggling available was
178 | trivial, I added it, too. But I am not using it.
179 |
180 | See [Keyboard shortcut customization (Input Method)](https://osamuaoki.github.io/en/2023/02/25/debian-usability-2023/#keyboard-shortcut-customization-input-method)
181 | and [GNOME shell extension for input methods](https://osamuaoki.github.io/en/2023/06/19/gnome-im-1/)
182 | for how I came to this extension.
183 |
184 | License
185 | =======
186 | Copyright (c) 2023 Osamu Aoki
187 |
188 | This program is free software; you can redistribute it and/or modify
189 | it under the terms of the GNU General Public License as published by
190 | the Free Software Foundation; either version 2 of the License, or
191 | (at your option) any later version.
192 |
193 | This program is distributed in the hope that it will be useful,
194 | but WITHOUT ANY WARRANTY; without even the implied warranty of
195 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
196 | GNU General Public License for more details.
197 |
198 | You should have received a copy of the GNU General Public License along
199 | with this program; if not, write to the Free Software Foundation, Inc.,
200 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
201 |
202 | [GPL2+](LICENSE)
203 |
204 |
--------------------------------------------------------------------------------
/extension.js:
--------------------------------------------------------------------------------
1 | import Gio from 'gi://Gio';
2 | import Meta from 'gi://Meta';
3 | import Shell from 'gi://Shell';
4 | import * as Keyboard from 'resource:///org/gnome/shell/ui/status/keyboard.js';
5 | import * as Main from 'resource:///org/gnome/shell/ui/main.js';
6 | import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
7 |
8 | const MAX_INPUT_METHODS = 10;
9 |
10 | export default class InputMethodSwitcher extends Extension {
11 | enable() {
12 | this.settings = this.getSettings();
13 | const InputSources = new Gio.Settings({ schema_id: 'org.gnome.desktop.input-sources' });
14 | const InputMethods = InputSources.get_value('sources');
15 | const nInputMethods = ((InputMethods.n_children() < MAX_INPUT_METHODS) ? InputMethods.n_children() : MAX_INPUT_METHODS);
16 | //
17 | this.i_base = -1; // start with invalid index to indicate no xkb set
18 | for (let i = 0; i < nInputMethods; i++) {
19 | let [type, _] = InputMethods.get_child_value(i).deepUnpack();
20 | if (type === "xkb") { // id isn't used
21 | if (this.i_base === -1) {
22 | this.i_base = i; // the first index for xkb
23 | };
24 | };
25 | };
26 | // i_base is the first xkb setting if 0 or plus value
27 | for (let i = 0; i < nInputMethods; i++) {
28 | let [type, _] = InputMethods.get_child_value(i).deepUnpack();
29 | Main.wm.addKeybinding(`imkey-${i}`,
30 | this.settings,
31 | Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
32 | Shell.ActionMode.ALL,
33 | () => {
34 | if (this.i_base === -1 || type === "xkb" || !this.settings.get_boolean('primary-xkb')) {
35 | Keyboard.getInputSourceManager().inputSources[i].activate();
36 | } else {
37 | Keyboard.getInputSourceManager().inputSources[this.i_base].activate();
38 | Keyboard.getInputSourceManager().inputSources[i].activate();
39 | };
40 | }
41 | );
42 | };
43 | // Touchpad control
44 | const Touchpad = new Gio.Settings({ schema_id: 'org.gnome.desktop.peripherals.touchpad' });
45 | // Emulate "gsettings set org.gnome.desktop.peripherals.touchpad send-events enabled"
46 | Main.wm.addKeybinding('tpkey-0',
47 | this.settings,
48 | Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
49 | Shell.ActionMode.ALL,
50 | () => Touchpad.set_string("send-events", "enabled")
51 | );
52 | // Emulate "gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled"
53 | Main.wm.addKeybinding('tpkey-1',
54 | this.settings,
55 | Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
56 | Shell.ActionMode.ALL,
57 | () => Touchpad.set_string("send-events", "disabled")
58 | );
59 | // Emulate "gsettings set org.gnome.desktop.peripherals.touchpad send-events enable/disabled"
60 | Main.wm.addKeybinding('tpkey-2',
61 | this.settings,
62 | Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
63 | Shell.ActionMode.ALL,
64 | () => {
65 | if (Touchpad.get_string("send-events") === "enabled") {
66 | Touchpad.set_string("send-events", "disabled");
67 | } else {
68 | Touchpad.set_string("send-events", "enabled");
69 | };
70 | }
71 | );
72 | };
73 |
74 | disable() {
75 | for (let i = 0; i < MAX_INPUT_METHODS; i++) {
76 | Main.wm.removeKeybinding(`imkey-${i}`);
77 | };
78 | Main.wm.removeKeybinding('tpkey-0');
79 | Main.wm.removeKeybinding('tpkey-1');
80 | Main.wm.removeKeybinding('tpkey-2');
81 | this.settings = null;
82 | };
83 | };
84 |
--------------------------------------------------------------------------------
/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "_generated": "Generated by SweetTooth, do not edit",
3 | "description": "Quick switching of input method and touchpad with user configurable shortcut binding",
4 | "name": "Input method and touchpad shortcuts",
5 | "settings-schema": "org.gnome.shell.extensions.inputmethod-shortcuts",
6 | "shell-version": [
7 | "45",
8 | "46",
9 | "47",
10 | "48",
11 | "49"
12 | ],
13 | "url": "https://github.com/osamuaoki/inputmethod-shortcuts",
14 | "uuid": "inputmethod-shortcuts@osamu.debian.org"
15 | }
16 |
--------------------------------------------------------------------------------
/pref-im-alt2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamuaoki/inputmethod-shortcuts/3bebd235a137bbe4478f9225187ac1b573a862fa/pref-im-alt2.png
--------------------------------------------------------------------------------
/pref-im.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamuaoki/inputmethod-shortcuts/3bebd235a137bbe4478f9225187ac1b573a862fa/pref-im.png
--------------------------------------------------------------------------------
/pref-op.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamuaoki/inputmethod-shortcuts/3bebd235a137bbe4478f9225187ac1b573a862fa/pref-op.png
--------------------------------------------------------------------------------
/pref-tp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamuaoki/inputmethod-shortcuts/3bebd235a137bbe4478f9225187ac1b573a862fa/pref-tp.png
--------------------------------------------------------------------------------
/prefs.js:
--------------------------------------------------------------------------------
1 | import Adw from 'gi://Adw';
2 | import Gtk from 'gi://Gtk';
3 | import Gdk from 'gi://Gdk';
4 | import Gio from 'gi://Gio';
5 | import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
6 |
7 | const MAX_INPUT_METHODS = 10;
8 | const MAX_TOUCHPADS = 3;
9 |
10 | export default class Preferences extends ExtensionPreferences {
11 | fillPreferencesWindow(window) {
12 | const settings = this.getSettings();
13 | const InputSources = new Gio.Settings({
14 | schema_id: 'org.gnome.desktop.input-sources'
15 | });
16 | const InputMethods = InputSources.get_value('sources');
17 | // nInputMethods : number of input method shortcuts managed (max 10)
18 | const nInputMethods = (
19 | (InputMethods.n_children() < MAX_INPUT_METHODS)
20 | ? InputMethods.n_children()
21 | : MAX_INPUT_METHODS
22 | );
23 | const im_labels = Array(nInputMethods);
24 | let id0_xkb = ''; // start with invalid index to indicate no xkb set
25 | let i0_xkb = -1; // start with invalid index to indicate no xkb set
26 | for (let i = 0; i < nInputMethods; i++) {
27 | let [type, id] = InputMethods.get_child_value(i).deepUnpack();
28 | im_labels[i] = `IM${i}: ${id} (${type})`;
29 | if (type === "xkb") {
30 | if (i0_xkb === -1) {
31 | id0_xkb = id;
32 | i0_xkb = i; // the first index for xkb
33 | };
34 | };
35 | };
36 | const tp_labels = Array(MAX_TOUCHPADS);
37 | tp_labels[0] = 'Touchpad On';
38 | tp_labels[1] = 'Touchpad Off';
39 | tp_labels[2] = 'Touchpad Toggle';
40 | addShortcutPage(window, settings,
41 | 'Input Method Shortcuts', 'input-keyboard-symbolic',
42 | 'imkey', im_labels, MAX_INPUT_METHODS
43 | );
44 | addShortcutPage(window, settings,
45 | 'Touchpad Shortcuts', 'input-touchpad-symbolic',
46 | 'tpkey', tp_labels, MAX_TOUCHPADS
47 | );
48 | addSwitchPage(window, settings,
49 | 'Operation Preference', 'preferences-system-symbolic', i0_xkb, id0_xkb
50 | );
51 | };
52 | }
53 |
54 | function addShortcutPage(window, settings, title, icon_name, prefix, labels, max) {
55 | // Create a preferences page
56 | const page = new Adw.PreferencesPage();
57 | page.set_title(title);
58 | page.set_icon_name(icon_name);
59 | window.add(page);
60 |
61 | // List of inputmethod settings as a group
62 | const group = new Adw.PreferencesGroup();
63 | page.add(group);
64 |
65 | // Create inputmethod setting rows, each with title and (right aligned) button
66 | const row = Array(labels.length)
67 | const button = Array(labels.length)
68 | for (let i = 0; i < labels.length; i++) {
69 | row[i] = new Adw.ActionRow({ title: `${labels[i]}`, use_markup: true });
70 | group.add(row[i]);
71 | button[i] = makeButton(`${prefix}-${i}`, settings);
72 | row[i].add_suffix(button[i]);
73 | row[i].activatable_widget = button[i];
74 | }
75 | // Ensue to unset unused shortcuts
76 | for (let i = labels.length; i < max; i++) {
77 | settings.set_strv(`${prefix}-${i}`, []);
78 | }
79 | // Extra text to explain
80 | const group_extra = new Adw.PreferencesGroup();
81 | page.add(group_extra);
82 | const row_extra = new Adw.ActionRow(
83 | {
84 | title: 'Click each row to set a new keyboard shortcut.\nPress Esc to cancel or Backspace to disable keyboard shortcut.', use_markup: true
85 | }
86 | );
87 | group_extra.add(row_extra)
88 |
89 | window._settings = settings;
90 | }
91 |
92 | function makeButton(shortcut_name, settings) {
93 | const button = new Gtk.Button();
94 | button.connect('clicked', () => {
95 | button.set_label('*** Enter unused shortcut key ***');
96 |
97 | const eventController = new Gtk.EventControllerKey();
98 | button.add_controller(eventController);
99 |
100 | eventController.connect('key-pressed', (_widget, keyval, keycode, state) => {
101 | let mask = state & Gtk.accelerator_get_default_mod_mask();
102 | mask &= ~Gdk.ModifierType.LOCK_MASK;
103 | if (mask === 0 && keyval === Gdk.KEY_Escape) {
104 | updateButton(button, shortcut_name, settings);
105 | return Gdk.EVENT_STOP;
106 | }
107 |
108 | if (mask === 0 && keyval === Gdk.KEY_BackSpace) {
109 | settings.set_strv(`${shortcut_name}`, []);
110 | updateButton(button, shortcut_name, settings);
111 | return Gdk.EVENT_STOP;
112 | }
113 |
114 | if (isBindingValid({ mask, keycode, keyval })) {
115 | const binding = Gtk.accelerator_name_with_keycode(
116 | null,
117 | keyval,
118 | keycode,
119 | mask
120 | );
121 | // console.log(` binding = ${binding}`);
122 | settings.set_strv(`${shortcut_name}`, [binding]);
123 | }
124 | return Gdk.EVENT_STOP;
125 |
126 | })
127 |
128 | button.show();
129 | })
130 |
131 | settings.connect(`changed::${shortcut_name}`, () => {
132 | updateButton(button, shortcut_name, settings);
133 | });
134 |
135 | updateButton(button, shortcut_name, settings);
136 |
137 | return button;
138 | }
139 |
140 | function updateButton(button, shortcut_name, settings) {
141 | const text = settings.get_strv(shortcut_name)[0];
142 | if (text) {
143 | button.set_label(text);
144 | }
145 | else {
146 | button.set_label('Disabled');
147 | };
148 | };
149 |
150 | // Core logic from https://gitlab.gnome.org/GNOME/gnome-control-center/-/blob/main/panels/keyboard/keyboard-shortcuts.c
151 | // Logic with *** are added here
152 | // keyvals are defined in /usr/include/gtk-4.0/gdk/gdkkeysyms.h
153 | // modifiers are defined as enums in /usr/include/gtk-4.0/gdk/gdkenums.h
154 | // gjs code from https://github.com/jqno/gnome-happy-appy-hotkey.git
155 | function keyvalIsForbidden(keyval) {
156 | return [
157 | // Navigation keys
158 | Gdk.KEY_Home,
159 | Gdk.KEY_Left,
160 | Gdk.KEY_Up,
161 | Gdk.KEY_Right,
162 | Gdk.KEY_Down,
163 | Gdk.KEY_Page_Up,
164 | Gdk.KEY_Page_Down,
165 | Gdk.KEY_End,
166 | Gdk.KEY_Tab,
167 |
168 | // Return
169 | Gdk.KEY_KP_Enter,
170 | Gdk.KEY_Return,
171 |
172 | Gdk.KEY_Mode_switch,
173 | ].includes(keyval);
174 | };
175 |
176 | // *** Only to be used with some Modifier-pressed
177 | function keyvalIsAcceptedCombo(keyval) {
178 | return [
179 | // Modifier keys
180 | Gdk.KEY_Shift_L,
181 | Gdk.KEY_Control_L,
182 | Gdk.KEY_Alt_L, // Normal case incl. after Control etc.
183 | Gdk.KEY_Meta_L, // after Shift
184 | Gdk.KEY_Super_L,
185 | Gdk.KEY_Shift_R,
186 | Gdk.KEY_Control_R,
187 | Gdk.KEY_Alt_R,
188 | Gdk.KEY_Meta_R,
189 | Gdk.KEY_Super_R,
190 | Gdk.KEY_ISO_Level3_Shift, // Alternate Character key
191 | Gdk.KEY_Multi_key, // Compose key
192 | Gdk.KEY_Menu,
193 | Gdk.KEY_Scroll_Lock, // *** This is debatable and may be skipped
194 | Gdk.KEY_Num_Lock, // *** This is debatable and may be skipped
195 | Gdk.KEY_Caps_Lock, // *** This is debatable and may be skipped
196 | ].includes(keyval);
197 | };
198 | // The above doesn't cause problem even if Caps_Lock is set to work as Control by GNOME Tweak
199 |
200 | function isBindingValid({ mask, keycode, keyval }) {
201 | if ((mask === 0 || mask === Gdk.ModifierType.SHIFT_MASK) && keycode !== 0) {
202 | if (
203 | (keyval >= Gdk.KEY_a && keyval <= Gdk.KEY_z)
204 | || (keyval >= Gdk.KEY_A && keyval <= Gdk.KEY_Z)
205 | || (keyval >= Gdk.KEY_0 && keyval <= Gdk.KEY_9)
206 | || (keyval >= Gdk.KEY_kana_fullstop && keyval <= Gdk.KEY_semivoicedsound)
207 | || (keyval >= Gdk.KEY_Arabic_comma && keyval <= Gdk.KEY_Arabic_sukun)
208 | || (keyval >= Gdk.KEY_Serbian_dje && keyval <= Gdk.KEY_Cyrillic_HARDSIGN)
209 | || (keyval >= Gdk.KEY_Greek_ALPHAaccent && keyval <= Gdk.KEY_Greek_omega)
210 | || (keyval >= Gdk.KEY_hebrew_doublelowline && keyval <= Gdk.KEY_hebrew_taf)
211 | || (keyval >= Gdk.KEY_Thai_kokai && keyval <= Gdk.KEY_Thai_lekkao)
212 | || (keyval >= Gdk.KEY_Hangul_Kiyeog && keyval <= Gdk.KEY_Hangul_J_YeorinHieuh)
213 | || (keyval === Gdk.KEY_space && mask === 0)
214 | || (keyval === Gdk.KEY_WakeUp && mask === 0) // *** Add for Thinkpad Fn-key
215 | || keyvalIsForbidden(keyval)
216 | ) {
217 | return false;
218 | };
219 | };
220 |
221 | // White list (basic Gtk) -- this takes care (mask && keyvalIsForbidden(keyval) cases
222 | // - Thinkpad Fn->Shift_R emitting Gdk.KEY_Launch3 is taken care here
223 | if (Gtk.accelerator_valid(keyval, mask)) {
224 | return true;
225 | };
226 | // *** Extra whitelist with some Modifier-pressed as combo
227 | if (mask && keyvalIsAcceptedCombo(keyval)) {
228 | return true;
229 | };
230 | // Default not allow
231 | return false;
232 | };
233 |
234 | function addSwitchPage(window, settings, title, icon_name, i0_xkb, id0_xkb) {
235 | // Create a preferences page
236 | const page = new Adw.PreferencesPage();
237 | page.set_title(title);
238 | page.set_icon_name(icon_name);
239 | window.add(page);
240 |
241 | // List of inputmethod settings as a group
242 | const group = new Adw.PreferencesGroup();
243 | page.add(group);
244 |
245 | // Step though primary xkb before setting ibus IM : default=ON
246 | let title_0 = '';
247 | if (i0_xkb >= 0) {
248 | title_0 = `Set to the first xkb (currently, IM${i0_xkb}: ${id0_xkb}) before using any ibus.\nThis is helpful when IM can select non-latin xkb.`;
249 | } else {
250 | title_0 = 'Nothing to configure (since no xkb are selected as IM)';
251 | }
252 | const row_0 = new Adw.ActionRow({
253 | title: title_0, use_markup: true
254 | });
255 | group.add(row_0);
256 | if (i0_xkb >= 0) {
257 | let primary_xkb = new Gtk.Switch({
258 | active: settings.get_boolean('primary-xkb'),
259 | halign: Gtk.Align.END,
260 | vexpand: false,
261 | hexpand: false,
262 | margin_top: 18,
263 | margin_bottom: 18
264 | })
265 | settings.bind('primary-xkb', primary_xkb, 'active', Gio.SettingsBindFlags.DEFAULT)
266 | row_0.add_suffix(primary_xkb);
267 | row_0.activatable_widget = primary_xkb;
268 | }
269 | // Extra text to explain
270 | const group_extra = new Adw.PreferencesGroup();
271 | page.add(group_extra);
272 | const row_extra = new Adw.ActionRow(
273 | {
274 | title: 'See https://github.com/osamuaoki/inputmethod-shortcuts for more.', use_markup: true
275 | }
276 | );
277 | group_extra.add(row_extra)
278 |
279 | window._settings = settings;
280 | }
281 |
--------------------------------------------------------------------------------
/schemas/org.gnome.shell.extensions.inputmethod-shortcuts.gschema.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ['']
6 | Shortcut to input method 0
7 |
8 |
9 | ['']
10 | Shortcut to input method 1
11 |
12 |
13 | ['']
14 | Shortcut to input method 2
15 |
16 |
17 | ['']
18 | Shortcut to input method 3
19 |
20 |
21 | ['']
22 | Shortcut to input method 4
23 |
24 |
25 | ['']
26 | Shortcut to input method 5
27 |
28 |
29 | ['']
30 | Shortcut to input method 6
31 |
32 |
33 | ['']
34 | Shortcut to input method 7
35 |
36 |
37 | ['']
38 | Shortcut to input method 8
39 |
40 |
41 | ['']
42 | Shortcut to input method 9
43 |
44 |
45 | ['']
46 | Shortcut to touchpad on
47 |
48 |
49 | ['']
50 | Shortcut to touchpad off
51 |
52 |
53 | ['']
54 | Shortcut to touchpad toggle
55 |
56 |
57 | true
58 | Set xkb to the first one before entering any ibus
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/test-keys/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/test-keys/Makefile:
--------------------------------------------------------------------------------
1 | UUID = test-keys@osamu.debian.org
2 | EXTENSIONS_PATH = ~/.local/share/gnome-shell/extensions
3 | INSTALL_PATH = $(EXTENSIONS_PATH)/$(UUID)
4 | FILES = README.md \
5 | LICENSE \
6 | extension.js \
7 | metadata.json \
8 | prefs.js \
9 | schemas/
10 |
11 | .PHONY: all build zip repo install clean
12 | all: build
13 |
14 | build:
15 | glib-compile-schemas --strict --targetdir=schemas/ schemas
16 |
17 | zip: build
18 | rm -f $(UUID).zip
19 | zip -r $(UUID).zip $(FILES)
20 |
21 | install: build
22 | rm -rf $(INSTALL_PATH)
23 | mkdir -p $(INSTALL_PATH)
24 | cp -r $(FILES) $(INSTALL_PATH)/
25 |
26 | clean:
27 | rm -f $(UUID).zip
28 | rm -f schemas/gschemas.compiled
29 | # vim: set ts=8:
30 |
--------------------------------------------------------------------------------
/test-keys/README.md:
--------------------------------------------------------------------------------
1 | Test keys
2 | =========
3 |
4 | This is a GNOME shell extension which only test keyboard input and capturing.
5 |
6 | Only used for the verification of development codes.
7 |
8 | License
9 | =======
10 | Copyright (c) 2023 Osamu Aoki
11 |
12 | This program is free software; you can redistribute it and/or modify
13 | it under the terms of the GNU General Public License as published by
14 | the Free Software Foundation; either version 2 of the License, or
15 | (at your option) any later version.
16 |
17 | This program is distributed in the hope that it will be useful,
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | GNU General Public License for more details.
21 |
22 | You should have received a copy of the GNU General Public License along
23 | with this program; if not, write to the Free Software Foundation, Inc.,
24 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 |
26 | [GPL2+](LICENSE)
27 |
28 |
--------------------------------------------------------------------------------
/test-keys/extension.js:
--------------------------------------------------------------------------------
1 | import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
2 |
3 | export default class TestKeysExtension extends Extension {
4 | enable() {
5 | this.settings = this.getSettings();
6 | };
7 |
8 | disable() {
9 | this.settings = null;
10 | };
11 | };
12 |
--------------------------------------------------------------------------------
/test-keys/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "shell-version": [ "45", "46", "47", "48" ],
3 | "uuid": "test-keys@osamu.debian.org",
4 | "name": "Test keys",
5 | "description": "Test keyboard input for any keys pressed",
6 | "url": "https://github.com/osamuaoki/test-keys",
7 | "settings-schema": "org.gnome.shell.extensions.test-keys"
8 | }
9 |
--------------------------------------------------------------------------------
/test-keys/prefs.js:
--------------------------------------------------------------------------------
1 | import Adw from 'gi://Adw';
2 | import Gtk from 'gi://Gtk';
3 | import Gdk from 'gi://Gdk';
4 | import Gio from 'gi://Gio';
5 | import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
6 |
7 | export default class Preferences extends ExtensionPreferences {
8 | fillPreferencesWindow(window) {
9 | const settings = this.getSettings();
10 | // Create a preferences page
11 | const page = new Adw.PreferencesPage();
12 | page.set_title('Test keys');
13 | page.set_icon_name('input-keyboard-symbolic');
14 | window.add(page);
15 |
16 | // List of inputmethod settings as a group
17 | const group = new Adw.PreferencesGroup();
18 | page.add(group);
19 |
20 | // Create inputmethod setting rows, each with title and (right aligned) button
21 | const row = new Adw.ActionRow({ title: `Test a key`, use_markup: true });
22 | group.add(row);
23 | const button = makeButton('key', settings);
24 | row.add_suffix(button);
25 | row.activatable_widget = button;
26 | // Extra text to explain
27 | const group_extra = new Adw.PreferencesGroup();
28 | page.add(group_extra);
29 | const row_extra = new Adw.ActionRow(
30 | {
31 | title: 'Click each row to set a new keyboard shortcut.\nPress Esc to cancel or Backspace to disable keyboard shortcut.\n\nkeycode = the hardware keycode. This is an identifying number for a physical key.\nkeyval = KEY CONSTANT ... Like ASCII\nmask = GDK3 ModifierType\n SHIFT_MASK\t\t= 0x1\n CONTROL_MASK\t= 0x4\n MOD1_MASK\t\t= 0x8 (ALT)\n SUPER_MASK\t\t= 0x400_0000\n HYPER_MASK\t\t= 0x800_0000\n META_MASK\t\t= 0x1000_0000\n ORDED_MASKSZZ\t= 0x1c00_000d',
32 | use_markup: true
33 | }
34 | );
35 | group_extra.add(row_extra)
36 | // Create a preferences page
37 |
38 | // List of inputmethod settings as a group
39 | const group_0 = new Adw.PreferencesGroup();
40 | page.add(group_0);
41 |
42 | // Step though primary xkb before setting ibus IM : default=ON
43 | const row_0 = new Adw.ActionRow({
44 | title: 'Set filter to limit key to valid shortcut keys',
45 | use_markup: true
46 | });
47 | group.add(row_0);
48 | let filter_mode = new Gtk.Switch({
49 | active: settings.get_boolean('filter-mode'),
50 | halign: Gtk.Align.END,
51 | vexpand: false,
52 | hexpand: false,
53 | margin_top: 18,
54 | margin_bottom: 18
55 | })
56 | settings.bind('filter-mode', filter_mode, 'active', Gio.SettingsBindFlags.DEFAULT)
57 | row_0.add_suffix(filter_mode);
58 | row_0.activatable_widget = filter_mode;
59 |
60 | window._settings = settings;
61 | }
62 | }
63 |
64 | function makeButton(shortcut_name, settings) {
65 | const button = new Gtk.Button();
66 | button.connect('clicked', () => {
67 | button.set_label('*** Enter unused shortcut key ***');
68 |
69 | const eventController = new Gtk.EventControllerKey();
70 | button.add_controller(eventController);
71 |
72 | eventController.connect('key-pressed', (_widget, keyval, keycode, state) => {
73 |
74 | let def_mask = Gtk.accelerator_get_default_mod_mask();
75 | let mask = state & Gtk.accelerator_get_default_mod_mask();
76 | // ignore a mask bit for Gdk.ModifierType.LOCK_MASK=2 https://gjs-docs.gnome.org/gdk30~3.0/gdk.modifiertype
77 | // Not found in GDK4
78 | mask &= ~Gdk.ModifierType.LOCK_MASK;
79 | if (mask === 0 && keyval === Gdk.KEY_Escape) {
80 | updateButton(button, shortcut_name, settings);
81 | return Gdk.EVENT_STOP;
82 | }
83 |
84 | if (mask === 0 && keyval === Gdk.KEY_BackSpace) {
85 | settings.set_strv(`${shortcut_name}`, []);
86 | updateButton(button, shortcut_name, settings);
87 | return Gdk.EVENT_STOP;
88 | }
89 |
90 | let filter_mode = settings.get_boolean('filter-mode');
91 | if (isBindingValid({ mask, keycode, keyval }) || !filter_mode) {
92 | const binding = Gtk.accelerator_name_with_keycode(
93 | null,
94 | keyval,
95 | keycode,
96 | mask
97 | );
98 | //settings.set_strv(`${shortcut_name}`, [binding]);
99 | // use [1] to retain parameter situation
100 | // keyval is ASCII for normal keys in US
101 | let mask_0 = (mask === 0);
102 | let mask_s = (mask === Gdk.ModifierType.SHIFT_MASK);
103 | let keycode_nz = (keycode !== 0);
104 | settings.set_strv(`${shortcut_name}`, [binding, ` keyval\t=0x${keyval.toString(16)}\n keycode\t=0x${keycode.toString(16)}\n mask\t\t=0x${mask.toString(16)}\n state\t\t=0x${state.toString(16)}\n def_mask\t=0x${def_mask.toString(16)}\n filter\t=${filter_mode}\n mask===0 ${mask_0} / mask===SHIFT ${mask_s} / keycode !== 0 ${keycode_nz}\n *** Gdk.SHIFT_MASK=${Gdk.SHIFT_MASK} / Gdk.ModifierType.SHIFT_MASK=${Gdk.ModifierType.SHIFT_MASK}`]);
105 | }
106 | return Gdk.EVENT_STOP;
107 |
108 | })
109 |
110 | button.show();
111 | })
112 |
113 | settings.connect(`changed::${shortcut_name}`, () => {
114 | updateButton(button, shortcut_name, settings);
115 | });
116 |
117 | updateButton(button, shortcut_name, settings);
118 |
119 | return button;
120 | }
121 |
122 | function updateButton(button, shortcut_name, settings) {
123 | const text = settings.get_strv(shortcut_name);
124 | if (text[0]) {
125 | if (text.length === 1) {
126 | button.set_label(text[0]);
127 | } else {
128 | button.set_label(`${text[0]}\n${text[1]}`);
129 | }
130 | }
131 | else {
132 | button.set_label('Disabled');
133 | };
134 | };
135 |
136 | // Core logic from https://gitlab.gnome.org/GNOME/gnome-control-center/-/blob/main/panels/keyboard/keyboard-shortcuts.c
137 | // Logic with *** are added here
138 | // keyvals are defined in /usr/include/gtk-4.0/gdk/gdkkeysyms.h
139 | // modifiers are defined as enums in /usr/include/gtk-4.0/gdk/gdkenums.h
140 | // gjs code from https://github.com/jqno/gnome-happy-appy-hotkey.git
141 |
142 | // Not to be used with or without SHIFT (Other Modifier-pressed are OK)
143 | function keyvalIsForbidden(keyval) {
144 | return [
145 | // Navigation keys
146 | Gdk.KEY_Home,
147 | Gdk.KEY_Left,
148 | Gdk.KEY_Up,
149 | Gdk.KEY_Right,
150 | Gdk.KEY_Down,
151 | Gdk.KEY_Page_Up,
152 | Gdk.KEY_Page_Down,
153 | Gdk.KEY_End,
154 | Gdk.KEY_Tab,
155 |
156 | // Return
157 | Gdk.KEY_KP_Enter,
158 | Gdk.KEY_Return,
159 |
160 | Gdk.KEY_Mode_switch,
161 | ].includes(keyval);
162 | };
163 |
164 | // // *** To be used even alone
165 | // function keyvalIsAcceptedEvenAlone(keyval) {
166 | // if (keyval >= Gdk.KEY_Kanji && keyval <= Gdk.KEY_Zenkaku_Hankaku) {
167 | // return true; // All Japanese keyboard
168 | // };
169 | // return [
170 | // Gdk.KEY_Caps_Lock,
171 | // ].includes(keyval);
172 | // };
173 | //
174 | // *** Only to be used with some Modifier-pressed
175 | function keyvalIsAcceptedCombo(keyval) {
176 | return [
177 | // Modifier keys
178 | Gdk.KEY_Shift_L,
179 | Gdk.KEY_Control_L,
180 | Gdk.KEY_Alt_L, // Normal case incl. after Control etc.
181 | Gdk.KEY_Meta_L, // after Shift
182 | Gdk.KEY_Super_L,
183 | Gdk.KEY_Shift_R,
184 | Gdk.KEY_Control_R,
185 | Gdk.KEY_Alt_R,
186 | Gdk.KEY_Meta_R,
187 | Gdk.KEY_Super_R,
188 | Gdk.KEY_ISO_Level3_Shift, // Alternate Character key
189 | Gdk.KEY_Multi_key, // Compose key
190 | Gdk.KEY_Menu,
191 | Gdk.KEY_Scroll_Lock, // *** This is debatable and may be skipped
192 | Gdk.KEY_Num_Lock, // *** This is debatable and may be skipped
193 | Gdk.KEY_Caps_Lock, // *** This is debatable and may be skipped
194 | ].includes(keyval);
195 | };
196 | // The above doesn't cause problem even if Caps_Lock is set to work as Control by GNOME Tweak
197 |
198 | //
199 | function isBindingValid({ mask, keycode, keyval }) {
200 | // Blacklist -- same logic as gnome-control-center
201 | if ((mask === 0 || mask === Gdk.ModifierType.SHIFT_MASK) && keycode !== 0) {
202 | if (
203 | (keyval >= Gdk.KEY_a && keyval <= Gdk.KEY_z)
204 | || (keyval >= Gdk.KEY_A && keyval <= Gdk.KEY_Z)
205 | || (keyval >= Gdk.KEY_0 && keyval <= Gdk.KEY_9)
206 | || (keyval >= Gdk.KEY_kana_fullstop && keyval <= Gdk.KEY_semivoicedsound)
207 | || (keyval >= Gdk.KEY_Arabic_comma && keyval <= Gdk.KEY_Arabic_sukun)
208 | || (keyval >= Gdk.KEY_Serbian_dje && keyval <= Gdk.KEY_Cyrillic_HARDSIGN)
209 | || (keyval >= Gdk.KEY_Greek_ALPHAaccent && keyval <= Gdk.KEY_Greek_omega)
210 | || (keyval >= Gdk.KEY_hebrew_doublelowline && keyval <= Gdk.KEY_hebrew_taf)
211 | || (keyval >= Gdk.KEY_Thai_kokai && keyval <= Gdk.KEY_Thai_lekkao)
212 | || (keyval >= Gdk.KEY_Hangul_Kiyeog && keyval <= Gdk.KEY_Hangul_J_YeorinHieuh)
213 | || (keyval === Gdk.KEY_space && mask === 0)
214 | || (keyval === Gdk.KEY_WakeUp && mask === 0) // *** Add for Thinkpad Fn-key
215 | || keyvalIsForbidden(keyval)
216 | ) {
217 | console.log(`blacklist ${mask.toString(16)} ${keyval}`);
218 | return false;
219 | };
220 | };
221 | // White list (basic Gtk) -- this takes care (mask && keyvalIsForbidden(keyval) cases
222 | // - Thinkpad Fn->Shift_R emitting Gdk.KEY_Launch3 is taken care here
223 | if (Gtk.accelerator_valid(keyval, mask)) {
224 | console.log(`whitelist-gtk ${mask.toString(16)} ${keyval}`);
225 | return true;
226 | };
227 | // *** Extra whitelist with some Modifier-pressed as combo
228 | if (mask && keyvalIsAcceptedCombo(keyval)) {
229 | console.log(`whitelist-ext-combo ${mask.toString(16)} ${keyval}`);
230 | return true;
231 | };
232 | // // *** Extra whitelist single key
233 | // if (keyvalIsAcceptedEvenAlone(keyval)) {
234 | // console.log(`whitelist-ext-single ${mask.toString(16)} ${keyval}`);
235 | // return true;
236 | // }
237 | // // Extra keyvalIsForbidden Modifier-pressed
238 | // if ( mask && keyvalIsForbidden(keyval) ) {
239 | // console.log(`test-ext-never ${mask.toString(16)} ${keyval}`);
240 | // return false;
241 | // };
242 | // Default not allow
243 | console.log(`default-never ${mask.toString(16)} ${keyval}`);
244 | return false;
245 | };
246 |
247 |
--------------------------------------------------------------------------------
/test-keys/schemas/org.gnome.shell.extensions.test-keys.gschema.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ['']
6 | Key pressed
7 |
8 |
9 | true
10 | Set filter mode
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------