summaryrefslogtreecommitdiffstats
path: root/extension.js
blob: 69095aa0589fde3061e6ddb5e29c2eff14e9519d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

// Extension to display a Fedora logo on Activities button

// Copyright (C) 2011 by Timur Kristóf <venemo@msn.com>

/* Licensed under the MIT license (copied from the http://en.wikipedia.org/wiki/MIT_License site)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. */

const St = imports.gi.St;
const Mainloop = imports.mainloop;
const Main = imports.ui.main;

// This is for debugging purposes
function _debugStuff() {
    let text = new St.Label({ text: Main.panel.button.get_style(), style: 'font-size: 10px; background: #000000; color: #ffffff;' });
    let monitor = global.get_primary_monitor();
    global.stage.add_actor(text);
    text.set_position(Math.floor (monitor.width / 2 - text.width / 2), Math.floor(monitor.height / 2 - text.height / 2));
    Mainloop.timeout_add(3000, function () { text.destroy(); });
}

// Extension initialization code - adding the Fedora logo :)
function main() {
    // The following lines can be used for debugging purposes
    //Main.panel.button.connect('button-release-event', _debugStuff);
    //Main.panel.actor.set_direction(St.TextDirection.RTL);
    
    // Getting the old style and using it as a base if it's not null
    let oldStyle = Main.panel.button.get_style();
    let newStyle = '';
    if (oldStyle != null)
        newStyle = oldStyle;
    
    // Let's care about both RTL and LTR directions
    let currentDirection = Main.panel.actor.get_direction();
    
    if (currentDirection == St.TextDirection.LTR) {
        newStyle += ' padding-left: 36px; background-image: url(/usr/share/icons/hicolor/24x24/apps/fedora-logo-icon.png); background-position: 8px 0px;';
    }
    else if (currentDirection == St.TextDirection.RTL) {
        newStyle += ' padding-right: 36px; background-image: url(/usr/share/icons/hicolor/24x24/apps/fedora-logo-icon.png); background-position: ' + Main.panel.button.width + 'px 0px;';
    }
    
    // Setting the new style to the button
    Main.panel.button.set_style(newStyle);
}