Git Product home page Git Product logo

gnome-optirun's Introduction

gnome-optirun

This GNOME extension adds an Optirun, a Primusrun and an Optiprime menu entries when right-clicking an application in the dash or in the activities overview. Selecting it will launch the application with Bumblebee's optirun command or the primusrun command if it is installed, without having to open a terminal and do it manually. The Optiprime one is using an optiprime script bundled with the extension. It launches the application with vblank_mode=0 and Primusrun.

Screenshot

gnome-optirun's People

Contributors

laurenttreguier avatar secondmain avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gnome-optirun's Issues

Optiprime script

Hi,
I just made a new update to your extension, because I saw that someone made a sort of fork to integrate with the optiprime script (but overwriting the possibility of using primusrun normally). For the sake of completeness, I modified the Optirun extension like in the past, making it able to manage all the three choices (optirun, primusrun and optiprime). Please integrate my code in the master branch if you like it and the behind idea...

The optiprime script must be created in the /usr/bin folder (and it will be made executable), and it looks like the following:

#! /bin/sh
vblank_mode=0 primusrun "$@"

Thanks a lot

Iade Gesso, MSc & PhD in Computer Science

Here the new code:

const Lang = imports.lang;
const Shell = imports.gi.Shell;
const GLib = imports.gi.GLib;
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;
const Util = imports.misc.util;

const extensionLocations = ["/usr", "~/.local"];

let Aim = imports.ui.appDisplay.AppIconMenu;
let origin;
let launcher_optiprime;
let launcher_primusrun;
let launcher_optirun;

function enable() {
    origin = Aim.prototype._redisplay;

    if (GLib.spawn_command_line_sync("which optiprime")[3] === 0) {
        launcher_optiprime = "Optiprime";
    }

    if (GLib.spawn_command_line_sync("which primusrun")[3] === 0) {
        launcher_primusrun = "Primusrun";
    }

    if (GLib.spawn_command_line_sync("which optirun")[3] === 0) {
        launcher_optirun = "Optirun";
    } else {
        Main.notifyError("gnome-optirun", "Error: Bumblebee is not installed");
        return;
    }

    Aim.prototype._redisplay = function () {
        origin.call(this, arguments);

        let i = 1;

	if (launcher_optiprime) {
            this._optiprime = new PopupMenu.PopupMenuItem(_(launcher_optiprime));
            this.addMenuItem(this._optiprime, this._getMenuItems().indexOf(this._newWindowMenuItem) + i);
            this._optiprime.connect("activate", Lang.bind(this, function () {
                if (this._source.app.state == Shell.AppState.STOPPED) {
                    this._source.animateLaunch();
                }

                Util.spawnApp([launcher_optiprime.toLowerCase(), _getCommand(this._source.app.get_id())]);
                this.emit('activate-window', null);
            }));
            ++i;
        }

        if (launcher_primusrun) {
            this._primusrun = new PopupMenu.PopupMenuItem(_(launcher_primusrun));
            this.addMenuItem(this._primusrun, this._getMenuItems().indexOf(this._newWindowMenuItem) + i);
            this._primusrun.connect("activate", Lang.bind(this, function () {
                if (this._source.app.state == Shell.AppState.STOPPED) {
                    this._source.animateLaunch();
                }

                Util.spawnApp([launcher_primusrun.toLowerCase(), _getCommand(this._source.app.get_id())]);
                this.emit('activate-window', null);
            }));
            ++i;
        }

        if (launcher_optirun) {
            this._optirun = new PopupMenu.PopupMenuItem(_(launcher_optirun));
            this.addMenuItem(this._optirun, this._getMenuItems().indexOf(this._newWindowMenuItem) + i);
            this._optirun.connect("activate", Lang.bind(this, function () {
                if (this._source.app.state == Shell.AppState.STOPPED) {
                    this._source.animateLaunch();
                }

                Util.spawnApp([launcher_optirun.toLowerCase(), _getCommand(this._source.app.get_id())]);
                this.emit('activate-window', null);
            }));
        }
    }
}

function disable() {
    Aim.prototype._redisplay = origin;
}

function _getCommand(file) {
    for (let i in extensionLocations) {
        try {
            let content = GLib.file_get_contents(extensionLocations[i] + "/share/applications/" + file)[1];
            let line = /Exec=.+/.exec(content)[0];

            return line.substr(5);
        } catch (error) {
            log(error);
        }
    }
}

Both launchers at the same time...

Some applications runs only with primusrun and other ones only using optirun: the solution... two launchers available at the same time...

I added a few lines of code to obtain my goal... so, I will share the modified file.

Iade

extension.js.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.