1
- const Lang = imports . lang
2
1
const Meta = imports . gi . Meta
3
- const Shell = imports . gi . Shell
4
2
const Main = imports . ui . main
5
3
const Mainloop = imports . mainloop ;
4
+ const Gio = imports . gi . Gio ;
6
5
7
6
let _close = 50 ;
8
7
var debug = false ;
@@ -11,57 +10,21 @@ var _log = function(){}
11
10
if ( debug )
12
11
_log = log . bind ( window . console ) ;
13
12
13
+ const Config = imports . misc . config ;
14
+ window . gsconnect = {
15
+ extdatadir : imports . misc . extensionUtils . getCurrentExtension ( ) . path ,
16
+ shell_version : parseInt ( Config . PACKAGE_VERSION . split ( '.' ) [ 1 ] , 10 )
17
+ } ;
18
+ imports . searchPath . unshift ( gsconnect . extdatadir ) ;
14
19
15
- const KeyManager = new Lang . Class ( {
16
- Name : 'MyKeyManager' ,
17
-
18
- _init : function ( ) {
19
- this . grabbers = new Map ( )
20
-
21
- global . display . connect (
22
- 'accelerator-activated' ,
23
- Lang . bind ( this , function ( display , action , deviceId , timestamp ) {
24
- _log ( 'Accelerator Activated: [display={}, action={}, deviceId={}, timestamp={}]' ,
25
- display , action , deviceId , timestamp )
26
- this . _onAccelerator ( action )
27
- } ) )
28
- } ,
29
-
30
- listenFor : function ( accelerator , callback ) {
31
- _log ( 'Trying to listen for hot key [accelerator={}]' , accelerator )
32
- let action = global . display . grab_accelerator ( accelerator )
33
-
34
- if ( action == Meta . KeyBindingAction . NONE ) {
35
- _log ( 'Unable to grab accelerator [binding={}]' , accelerator )
36
- } else {
37
- _log ( 'Grabbed accelerator [action={}]' , action )
38
- let name = Meta . external_binding_name_for_action ( action )
39
- _log ( 'Received binding name for action [name={}, action={}]' ,
40
- name , action )
41
-
42
- _log ( 'Requesting WM to allow binding [name={}]' , name )
43
- Main . wm . allowKeybinding ( name , Shell . ActionMode . ALL )
44
-
45
- this . grabbers . set ( action , {
46
- name : name ,
47
- accelerator : accelerator ,
48
- callback : callback ,
49
- action : action
50
- } )
51
- }
52
-
53
- } ,
54
-
55
- _onAccelerator : function ( action ) {
56
- let grabber = this . grabbers . get ( action )
57
-
58
- if ( grabber ) {
59
- this . grabbers . get ( action ) . callback ( )
60
- } else {
61
- _log ( 'No listeners [action={}]' , action )
62
- }
63
- }
64
- } )
20
+ const KeyBindings = imports . keybindings
21
+ let keyManager = new KeyBindings . Manager ( ) ;
22
+ var oldbindings = {
23
+ unmaximize : [ ] ,
24
+ maximize : [ ] ,
25
+ toggle_tiled_left : [ ] ,
26
+ toggle_tiled_right : [ ]
27
+ }
65
28
66
29
function isClose ( a , b ) {
67
30
if ( a <= b && a > b - _close )
@@ -304,17 +267,48 @@ function requestMove(direction) {
304
267
} ) ;
305
268
}
306
269
270
+ function changeBinding ( settings , key , oldBinding , newBinding ) {
271
+ var binding = oldbindings [ key . replace ( / - / g, '_' ) ] ;
272
+ var _newbindings = [ ] ;
273
+ for ( var i = 0 ; i < binding . length ; i ++ ) {
274
+ let currentbinding = binding [ i ] ;
275
+ if ( currentbinding == oldBinding )
276
+ currentbinding = newBinding ;
277
+ _newbindings . push ( currentbinding )
278
+ }
279
+ settings . set_strv ( key , _newbindings ) ;
280
+ }
281
+
282
+ function resetBinding ( settings , key ) {
283
+ var binding = oldbindings [ key . replace ( / - / g, '_' ) ] ;
284
+ settings . set_strv ( key , binding ) ;
285
+ }
286
+
307
287
var enable = function ( ) {
308
- let modifier = "<ctrl><super><shift>" ;
309
- let modifier2 = "<super>" ;
310
- let keyManager = new KeyManager ( )
311
- keyManager . listenFor ( modifier + "left" , function ( ) { requestMove ( "left" ) } )
312
- keyManager . listenFor ( modifier + "right" , function ( ) { requestMove ( "right" ) } )
313
- keyManager . listenFor ( modifier + "up" , function ( ) { requestMove ( "up" ) } )
314
- keyManager . listenFor ( modifier + "down" , function ( ) { requestMove ( "down" ) } )
315
- keyManager . listenFor ( modifier2 + "left" , function ( ) { requestMove ( "left" ) } )
316
- keyManager . listenFor ( modifier2 + "right" , function ( ) { requestMove ( "right" ) } )
317
- keyManager . listenFor ( modifier2 + "up" , function ( ) { requestMove ( "up" ) } )
318
- keyManager . listenFor ( modifier2 + "down" , function ( ) { requestMove ( "down" ) } )
288
+ let desktopSettings = new Gio . Settings ( { schema_id : 'org.gnome.desktop.wm.keybindings' } ) ;
289
+ let mutterSettings = new Gio . Settings ( { schema_id : 'org.gnome.mutter.keybindings' } ) ;
290
+ oldbindings [ 'unmaximize' ] = desktopSettings . get_strv ( 'unmaximize' ) ;
291
+ oldbindings [ 'maximize' ] = desktopSettings . get_strv ( 'maximize' ) ;
292
+ oldbindings [ 'toggle_tiled_left' ] = mutterSettings . get_strv ( 'toggle-tiled-left' ) ;
293
+ oldbindings [ 'toggle_tiled_right' ] = mutterSettings . get_strv ( 'toggle-tiled-right' ) ;
294
+ changeBinding ( desktopSettings , 'unmaximize' , '<Super>Down' , '<Control><Shift><Super>Down' ) ;
295
+ changeBinding ( desktopSettings , 'maximize' , '<Super>Up' , '<Control><Shift><Super>Up' ) ;
296
+ changeBinding ( mutterSettings , 'toggle-tiled-left' , '<Super>Left' , '<Control><Shift><Super>Left' ) ;
297
+ changeBinding ( mutterSettings , 'toggle-tiled-right' , '<Super>Right' , '<Control><Shift><Super>Right' ) ;
298
+ Mainloop . timeout_add ( 3000 , function ( ) {
299
+ keyManager . add ( "<Super>left" , function ( ) { requestMove ( "left" ) } )
300
+ keyManager . add ( "<Super>right" , function ( ) { requestMove ( "right" ) } )
301
+ keyManager . add ( "<Super>up" , function ( ) { requestMove ( "up" ) } )
302
+ keyManager . add ( "<Super>down" , function ( ) { requestMove ( "down" ) } )
303
+ } ) ;
319
304
}
320
305
306
+ var disable = function ( ) {
307
+ keyManager . removeAll ( ) ;
308
+ let desktopSettings = new Gio . Settings ( { schema_id : 'org.gnome.desktop.wm.keybindings' } ) ;
309
+ let mutterSettings = new Gio . Settings ( { schema_id : 'org.gnome.mutter.keybindings' } ) ;
310
+ resetBinding ( desktopSettings , 'unmaximize' ) ;
311
+ resetBinding ( desktopSettings , 'maximize' ) ;
312
+ resetBinding ( mutterSettings , 'toggle-tiled-left' ) ;
313
+ resetBinding ( mutterSettings , 'toggle-tiled-right' ) ;
314
+ }
0 commit comments