Last active
September 5, 2017 00:38
-
-
Save itzexor/c77ce9d4d4690f25d39818cc24d52a94 to your computer and use it in GitHub Desktop.
open windows search provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"description": "Searches open windows", | |
"uuid": "open-windows@exor", | |
"name": "Open Windows Search Provider" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Main = imports.ui.main; | |
const Meta = imports.gi.Meta; | |
const Cinnamon = imports.gi.Cinnamon; | |
const St = imports.gi.St; | |
const TRACKER = Cinnamon.WindowTracker.get_default(); | |
const DEFAULT_ICON = new St.Icon({ icon_name: 'application-default-icon', icon_type: St.IconType.FULLCOLOR, icon_size: 16 }); | |
function perform_search(pattern){ | |
let results = []; | |
let windows = global.display.list_windows(Meta.ListWindowsFlags.DEFAULT); | |
pattern = pattern.toLowerCase(); | |
for (let i = 0; i < windows.length; i++) { | |
if (Main.isInteresting(windows[i]) | |
&& typeof windows[i].title === "string" | |
&& windows[i].title.toLowerCase().indexOf(pattern) >= 0) { | |
let window_app = TRACKER.get_window_app(windows[i]); | |
let cur_result = {type: "window", | |
label: _("Open Window: %s").format(windows[i].title), | |
metaWindow: windows[i]}; | |
if (window_app) | |
cur_result.icon_app = window_app; | |
else | |
cur_result.icon = DEFAULT_ICON; | |
results.push(cur_result); | |
} | |
} | |
send_results(results); | |
} | |
function on_result_selected(result) { | |
result.metaWindow.activate(global.get_current_time()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment