Skip to content

Commit 4c9b6df

Browse files
committed
feat(launcher): Close launcher on mouse click
1 parent 2a01fb8 commit 4c9b6df

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

src/dialog_launcher.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
//@ts-ignore
22
const Me = imports.misc.extensionUtils.getCurrentExtension();
33

4-
const { Clutter, Gio, GLib, Meta } = imports.gi;
5-
64
import * as app_info from 'app_info';
75
import * as error from 'error';
6+
import * as launch from 'launcher_service';
7+
import * as levenshtein from 'levenshtein';
88
import * as lib from 'lib';
99
import * as log from 'log';
10+
import * as plugins from 'launcher_plugins';
1011
import * as result from 'result';
1112
import * as search from 'dialog_search';
12-
import * as launch from 'launcher_service';
13-
import * as plugins from 'launcher_plugins';
14-
import * as levenshtein from 'levenshtein';
1513

16-
import type { ShellWindow } from 'window';
17-
import type { Ext } from 'extension';
1814
import type { AppInfo } from 'app_info';
15+
import type { Ext } from 'extension';
16+
import type { ShellWindow } from 'window';
17+
18+
const { Clutter, Gio, GLib, Meta } = imports.gi
1919

2020
const { OK } = result;
2121

@@ -42,7 +42,7 @@ export class Launcher extends search.Search {
4242
desktop_apps: Array<[string, AppInfo]>
4343
service: launch.LauncherService
4444
last_plugin: null | plugins.Plugin.Source
45-
mode: number;
45+
mode: number
4646

4747
constructor(ext: Ext) {
4848
let cancel = () => {
@@ -114,14 +114,16 @@ export class Launcher extends search.Search {
114114
if (retain) {
115115
const generic = app.generic_name();
116116

117-
this.options.push(new launch.SearchOption(
117+
const button = new launch.SearchOption(
118118
app.name(),
119119
generic ? generic + " — " + where : where,
120120
'application-default-symbolic',
121121
{ gicon: app.icon() },
122122
this.icon_size(),
123123
{ app }
124-
))
124+
)
125+
126+
this.options.push(button)
125127
}
126128
}
127129

src/dialog_search.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const Me = imports.misc.extensionUtils.getCurrentExtension();
33

44
import * as Lib from 'lib';
5+
import * as rect from 'rectangle';
6+
57
import { SearchOption } from 'launcher_service';
68

79
const { Clutter, Shell, St } = imports.gi;
@@ -160,6 +162,28 @@ export class Search {
160162

161163
// Ensure that the width is at least 640 pixels wide.
162164
this.dialog.contentLayout.width = Math.max(Lib.current_monitor().width / 4, 640);
165+
166+
const id = global.stage.connect('event', (_actor: any, event: any) => {
167+
const { width, height } = this.dialog.dialogLayout._dialog;
168+
const { x, y } = this.dialog.dialogLayout
169+
const area = new rect.Rectangle([x, y, width, height]);
170+
171+
const close = this.dialog.visible
172+
&& (event.type() == Clutter.EventType.BUTTON_PRESS)
173+
&& !area.contains(Lib.cursor_rect())
174+
175+
if (close) {
176+
this.reset()
177+
this.close()
178+
this.cancel_cb()
179+
}
180+
181+
return Clutter.EVENT_PROPAGATE;
182+
})
183+
184+
this.dialog.connect('destroy', () => {
185+
global.stage.disconnect(id)
186+
})
163187
}
164188

165189
activate_option(id: number) {

0 commit comments

Comments
 (0)