forked from soutade/GnomeShellGenericMonitor
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ca11b0e175 | |||
| d0e8f0cde5 | |||
| 66d79cc804 | |||
| 3ed3394a33 | |||
| 7cd668af14 | |||
| 5690307c63 | |||
| b1feb004e8 | |||
| 73021a25a1 | |||
| 4c73986596 | |||
| d3665f2ff0 | |||
| 00fb6120c9 | |||
| 02d3e8b72a | |||
| 78254a550e | |||
| 7a5f506c23 | |||
| 1d3328f71e | |||
| 45d0cc9d11 | |||
| 4d6fe82790 | |||
| 9943a9075f | |||
| 83609b58ab | |||
| b85ff4a782 | |||
| 30bfc796b9 | |||
| 35e34b52f2 | |||
| 1b4430c3ac |
@@ -7,6 +7,10 @@ This GNOME Shell Extension aims to display information to center box. Using DBUS
|
||||
Installation
|
||||
------------
|
||||
|
||||
Install it from https://extensions.gnome.org/extension/2826/generic-monitor/
|
||||
|
||||
OR
|
||||
|
||||
Create a symbolic link from your _.local_ directory and enable extension
|
||||
|
||||
ln -s $PWD/generic-monitor@gnome-shell-extensions/ ~/.local/share/gnome-shell/extensions/
|
||||
@@ -67,6 +71,8 @@ DBUS object
|
||||
|
||||
<text_object> is defined as :
|
||||
"text" : {
|
||||
"name" : "" // Optional, used with popup nested element
|
||||
<signals_description>, // Optional, used with popup nested element
|
||||
"text" : "Text to be displayed",
|
||||
"style" : "CSS style to be applied", // Optional
|
||||
}
|
||||
@@ -79,6 +85,8 @@ DBUS object
|
||||
|
||||
<picture_object> is defined as :
|
||||
"picture" : {
|
||||
"name" : "" // Optional, used with popup nested element
|
||||
<signals_description>, // Optional, used with popup nested element
|
||||
"path" : "Icon path",
|
||||
"width" : XXX, // Optional : Force width in pixels, can be -1 for defaut value
|
||||
"height" : XXX, // Optional : Force height in pixels, can be -1 for defaut value
|
||||
@@ -105,11 +113,11 @@ Signals can be :
|
||||
|
||||
Targets :
|
||||
|
||||
* signal : emit a signal to desktop application
|
||||
* delete : Delete item
|
||||
* open-popup : Open the popup if there is one
|
||||
* close-popup : Close the popup if there is one
|
||||
* toggle-popup : Toggle (open/close) the popup if there is one
|
||||
* signal : Emit a signal to desktop application
|
||||
* delete : Delete item
|
||||
* open-popup : Open the popup if there is one
|
||||
* close-popup : Close the popup if there is one
|
||||
* toggle-popup : Toggle (open/close) the popup if there is one
|
||||
|
||||
|
||||
Signal names emit when action "signal" is specified :
|
||||
@@ -124,6 +132,8 @@ Signal names emit when action "signal" is specified :
|
||||
* onScrollDown
|
||||
|
||||
Each signal is sent with one parameter : "<itemName>@<groupName>"
|
||||
For popup nested elements, parameter is "<nestedName>@<itemName>@<groupName>"
|
||||
where nestedName can be empty if not defined by user
|
||||
|
||||
Other signals are available when extension is activated/deactivated :
|
||||
|
||||
@@ -136,11 +146,11 @@ Example
|
||||
|
||||
You can test it with command line :
|
||||
|
||||
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.notify '{"group":"new","items":[{"name":"first","on-click":"toggle-popup","text":"Hello","style":"color:green","popup":{"items":[{"picture":{"path":"/tmp/cat2.jpg"}}]}}]}'
|
||||
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.notify '{"group":"new","items":[{"name":"first","on-click":"toggle-popup","text":{"text":"Hello","style":"color:green"},"popup":{"items":[{"picture":{"path":"/tmp/cat.jpg"}}]}}]}'
|
||||
|
||||
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.deleteGroups '{"groups":["new"]}'
|
||||
|
||||
Python examples is available
|
||||
Python examples are available @ https://indefero.soutade.fr/p/genericmonitor/source/tree/master/examples
|
||||
|
||||
|
||||
Development
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
<interface name="com.soutade.GenericMonitor">
|
||||
<!-- Functions -->
|
||||
<method name="notify">
|
||||
<arg type="s" direction="in" />
|
||||
<arg name="parameters" type="s" direction="in" />
|
||||
</method>
|
||||
<method name="deleteItems">
|
||||
<arg type="s" direction="in" />
|
||||
<arg name="items" type="s" direction="in" />
|
||||
</method>
|
||||
<method name="deleteGroups">
|
||||
<arg type="s" direction="in" />
|
||||
<arg name="groups" type="s" direction="in" />
|
||||
</method>
|
||||
<method name="openPopup">
|
||||
<arg type="s" direction="in" />
|
||||
<arg name="popup" type="s" direction="in" />
|
||||
</method>
|
||||
<method name="closePopup">
|
||||
<arg type="s" direction="in" />
|
||||
<arg name="popup" type="s" direction="in" />
|
||||
</method>
|
||||
<method name="togglePopup">
|
||||
<arg type="s" direction="in" />
|
||||
<arg name="popup" type="s" direction="in" />
|
||||
</method>
|
||||
<!-- Events -->
|
||||
<signal name="onClick">
|
||||
<arg type="s" direction="out" />
|
||||
<arg name="fullName" type="s" direction="out" />
|
||||
</signal>
|
||||
<signal name="onRightClick">
|
||||
<arg type="s" direction="out" />
|
||||
<arg name="fullName" type="s" direction="out" />
|
||||
</signal>
|
||||
<signal name="onDblClick">
|
||||
<arg type="s" direction="out" />
|
||||
<arg name="fullName" type="s" direction="out" />
|
||||
</signal>
|
||||
<signal name="onRightDblClick">
|
||||
<arg type="s" direction="out" />
|
||||
<arg name="fullName" type="s" direction="out" />
|
||||
</signal>
|
||||
<signal name="onScrollUp">
|
||||
<arg type="s" direction="out" />
|
||||
<arg name="fullName" type="s" direction="out" />
|
||||
</signal>
|
||||
<signal name="onScrollDown">
|
||||
<arg type="s" direction="out" />
|
||||
<arg name="fullName" type="s" direction="out" />
|
||||
</signal>
|
||||
<signal name="onEnter">
|
||||
<arg type="s" direction="out" />
|
||||
<arg name="fullName" type="s" direction="out" />
|
||||
</signal>
|
||||
<signal name="onLeave">
|
||||
<arg type="s" direction="out" />
|
||||
<arg name="fullName" type="s" direction="out" />
|
||||
</signal>
|
||||
<!-- Activate/Deactivate signals -->
|
||||
<signal name="onActivate">
|
||||
|
||||
+39
-16
@@ -235,11 +235,25 @@ class GenericMonitor:
|
||||
class GenericMonitorGenericWidget:
|
||||
""" Generic widget class, parent of all widgets
|
||||
"""
|
||||
def __init__(self):
|
||||
self.valuesToMap = []
|
||||
def __init__(self, style='', name='', signals={}):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
name : str, optional
|
||||
Widget name
|
||||
signals : dictionary, optional
|
||||
Dictionary of signals and their action
|
||||
"""
|
||||
self.valuesToMap = ['name', 'style']
|
||||
self.mapValues = {}
|
||||
self.mapName = ''
|
||||
self.style = style
|
||||
self.name = name
|
||||
self.signals = signals
|
||||
|
||||
def setStyle(self, style):
|
||||
self.style = style
|
||||
|
||||
def _toMap(self):
|
||||
""" Return dictionary of class elements to send to addon
|
||||
"""
|
||||
@@ -247,12 +261,14 @@ class GenericMonitorGenericWidget:
|
||||
for p in self.valuesToMap:
|
||||
if self.__dict__[p]:
|
||||
self.mapValues[p] = self.__dict__[p]
|
||||
for (name, value) in self.signals.items():
|
||||
self.mapValues[name] = value
|
||||
return {self.mapName:self.mapValues}
|
||||
|
||||
class GenericMonitorTextWidget(GenericMonitorGenericWidget):
|
||||
""" Text widget
|
||||
"""
|
||||
def __init__(self, text, style=''):
|
||||
def __init__(self, text, style='', name='', signals={}):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
@@ -260,19 +276,20 @@ class GenericMonitorTextWidget(GenericMonitorGenericWidget):
|
||||
Text to display
|
||||
style : str, optional
|
||||
CSS style
|
||||
name : str, optional
|
||||
Widget name
|
||||
signals : dictionary, optional
|
||||
Dictionary of signals and their action
|
||||
"""
|
||||
self.valuesToMap = ('text', 'style')
|
||||
super().__init__(style, name, signals)
|
||||
self.valuesToMap += ['text']
|
||||
self.mapName = 'text'
|
||||
|
||||
self.text = text
|
||||
self.style = style
|
||||
|
||||
def setText(self, text):
|
||||
self.text = text
|
||||
|
||||
def setStyle(self, style):
|
||||
self.style = style
|
||||
|
||||
class GenericMonitorIconWidget(GenericMonitorGenericWidget):
|
||||
""" Icon widget
|
||||
"""
|
||||
@@ -285,7 +302,8 @@ class GenericMonitorIconWidget(GenericMonitorGenericWidget):
|
||||
style : str, optional
|
||||
CSS style
|
||||
"""
|
||||
self.valuesToMap = ('path', 'style')
|
||||
super().__init__(style=style)
|
||||
self.valuesToMap += ['path']
|
||||
self.mapName = 'icon'
|
||||
|
||||
self.path = path
|
||||
@@ -293,15 +311,12 @@ class GenericMonitorIconWidget(GenericMonitorGenericWidget):
|
||||
|
||||
def setPath(self, path):
|
||||
self.path = path
|
||||
|
||||
def setStyle(self, style):
|
||||
self.style = style
|
||||
|
||||
|
||||
class GenericMonitorPictureWidget(GenericMonitorIconWidget):
|
||||
class GenericMonitorPictureWidget(GenericMonitorGenericWidget):
|
||||
""" Picture widget
|
||||
"""
|
||||
def __init__(self, path, style='', width=-1, height=-1):
|
||||
def __init__(self, path, style='', width=-1, height=-1, name='', signals={}):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
@@ -313,15 +328,23 @@ class GenericMonitorPictureWidget(GenericMonitorIconWidget):
|
||||
Width of displayed picture (-1 for default width)
|
||||
height : int, optional
|
||||
Width of displayed picture (-1 for default width)
|
||||
name : str, optional
|
||||
Widget name
|
||||
signals : dictionary, optional
|
||||
Dictionary of signals and their action
|
||||
"""
|
||||
|
||||
super().__init__(path, style)
|
||||
self.valuesToMap = ('path', 'style', 'width', 'height')
|
||||
super().__init__(style, name, signals)
|
||||
self.valuesToMap += ['path', 'width', 'height']
|
||||
self.mapName = 'picture'
|
||||
self.path = path
|
||||
|
||||
self.width = width
|
||||
self.height = height
|
||||
|
||||
def setPath(self, path):
|
||||
self.path = path
|
||||
|
||||
def setWidth(self, width):
|
||||
self.width = width
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#
|
||||
# Copyright 2018 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#
|
||||
# Setup : https://developers.google.com/gmail/api/quickstart/python
|
||||
# Need to have credentials.json were you call main script
|
||||
#
|
||||
# File imported from https://github.com/googleworkspace/python-samples/blob/main/gmail/quickstart/quickstart.py
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os.path
|
||||
import json
|
||||
|
||||
from google.auth.transport.requests import Request
|
||||
from google.oauth2.credentials import Credentials
|
||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||
from googleapiclient.discovery import build
|
||||
|
||||
# If modifying these scopes, delete the file token.json.
|
||||
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
|
||||
|
||||
creds = None
|
||||
|
||||
def _initCreds():
|
||||
global creds
|
||||
if creds: return
|
||||
|
||||
# The file token.json stores the user's access and refresh tokens, and is
|
||||
# created automatically when the authorization flow completes for the first
|
||||
# time.
|
||||
if os.path.exists('token.json'):
|
||||
creds = Credentials.from_authorized_user_file('./token.json', SCOPES)
|
||||
# If there are no (valid) credentials available, let the user log in.
|
||||
if not creds or not creds.valid:
|
||||
if creds and creds.expired and creds.refresh_token:
|
||||
creds.refresh(Request())
|
||||
else:
|
||||
flow = InstalledAppFlow.from_client_secrets_file(
|
||||
'credentials.json', SCOPES)
|
||||
creds = flow.run_local_server(port=0)
|
||||
# Save the credentials for the next run
|
||||
with open('token.json', 'w') as token:
|
||||
data = {}
|
||||
data['refresh_token'] = creds.refresh_token
|
||||
data['client_id'] = creds.client_id
|
||||
data['client_secret'] = creds.client_secret
|
||||
data['token_uri'] = creds.token_uri
|
||||
data['id_token'] = creds.id_token
|
||||
token.write(json.dumps(data))
|
||||
|
||||
def getUnreadMails():
|
||||
"""
|
||||
Get number of unread threads (that may contain multiple messages)
|
||||
"""
|
||||
|
||||
_initCreds()
|
||||
|
||||
service = build('gmail', 'v1', credentials=creds)
|
||||
pageToken = ''
|
||||
threads = set()
|
||||
while True:
|
||||
results = service.users().messages().list(userId='me', labelIds=['UNREAD'],\
|
||||
includeSpamTrash=False, pageToken=pageToken)\
|
||||
.execute()
|
||||
if not 'messages' in results.keys(): continue
|
||||
threads = threads.union(set([k['threadId'] for k in results['messages']]))
|
||||
# Loop over all result pages (100 results per page by default)
|
||||
pageToken = results.get('nextPageToken', '')
|
||||
if not pageToken: break
|
||||
|
||||
return len(threads)
|
||||
+10
-20
@@ -23,11 +23,11 @@ import time
|
||||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
import xml.dom.minidom
|
||||
import getpass
|
||||
from threading import Thread
|
||||
from signal import signal, SIGINT
|
||||
import sys
|
||||
from genericmonitor import *
|
||||
from gmail import getUnreadMails
|
||||
|
||||
PURPLE_CONV_UPDATE_UNSEEN = 4
|
||||
PURPLE_MESSAGE_SEND = 0
|
||||
@@ -59,31 +59,23 @@ class PidginConversation:
|
||||
|
||||
class EventThread(Thread,GenericMonitor):
|
||||
SLEEP_TIME = 30
|
||||
MAIL_ADDRESS='XXX@gmail.com'
|
||||
|
||||
def stop(self):
|
||||
self._stopLoop = True
|
||||
self.stopMainLoop()
|
||||
|
||||
def _getMail(self):
|
||||
address = "https://mail.google.com/mail/feed/atom"
|
||||
auth = HTTPBasicAuth(self.MAIL_ADDRESS, self._mail_password)
|
||||
req = requests.get(address, auth=auth)
|
||||
text = ''
|
||||
style = ''
|
||||
if req.status_code == requests.codes.ok:
|
||||
dom = xml.dom.minidom.parseString(req.text)
|
||||
try:
|
||||
nb_messages = int(dom.getElementsByTagName('fullcount')[0].firstChild.nodeValue)
|
||||
if nb_messages == 1:
|
||||
text = '1 msg'
|
||||
elif nb_messages > 1:
|
||||
text = '%d msgs' % (nb_messages)
|
||||
style = 'color:white'
|
||||
except Exception as e:
|
||||
text = str(e)
|
||||
else:
|
||||
text = 'Mail error %d' % (req.status_code)
|
||||
try:
|
||||
nb_messages = getUnreadMails()
|
||||
if nb_messages == 1:
|
||||
text = '1 msg'
|
||||
elif nb_messages > 1:
|
||||
text = '%d msgs' % (nb_messages)
|
||||
style = 'color:white'
|
||||
except Exception as e:
|
||||
text = str(e)
|
||||
|
||||
self.mailWidget.setText(text)
|
||||
self.mailWidget.setStyle(style)
|
||||
@@ -103,8 +95,6 @@ class EventThread(Thread,GenericMonitor):
|
||||
self.add_signal_receiver(self.pidginMessageWrote, 'WroteChatMsg', 'im.pidgin.purple.PurpleInterface')
|
||||
self.add_signal_receiver(self.pidginConversationUpdated, 'ConversationUpdated', 'im.pidgin.purple.PurpleInterface')
|
||||
|
||||
self._mail_password = getpass.getpass('Enter password for address %s: ' % (self.MAIL_ADDRESS))
|
||||
|
||||
self.mailWidget = GenericMonitorTextWidget('')
|
||||
mailItem = GenericMonitorItem('mail', [self.mailWidget])
|
||||
self.mailGroup = GenericMonitorGroup('Mail', [mailItem])
|
||||
|
||||
+10
-8
@@ -19,6 +19,7 @@
|
||||
Display random picture from unsplash.com in a popup
|
||||
|
||||
* Click : open/close popup
|
||||
* Popup item click : display who clicked
|
||||
* ScrollUp/ScrollDown/Double click : display next picture
|
||||
* Right click : exit
|
||||
'''
|
||||
@@ -42,20 +43,17 @@ class PicturePopup(GenericMonitor):
|
||||
self.runMainLoop()
|
||||
|
||||
def display_next_img(self):
|
||||
filedata = urllib.request.urlopen('https://source.unsplash.com/random')
|
||||
# Get redirected URL without parameters
|
||||
url = filedata.url.split('?')[0]
|
||||
filedata = urllib.request.urlopen(url + '?fit=max&width=500&height=500')
|
||||
filedata = urllib.request.urlopen('https://picsum.photos/500/500')
|
||||
datatowrite = filedata.read()
|
||||
with open('/tmp/cat2.jpg', 'wb') as f:
|
||||
f.write(datatowrite)
|
||||
widget = GenericMonitorTextWidget('#%d' % self.imgs_idx, 'color:purple')
|
||||
url_widget = GenericMonitorTextWidget(url, 'color:white;font-weight:bold')
|
||||
picture_widget = GenericMonitorPictureWidget('/tmp/cat2.jpg')
|
||||
url_widget = GenericMonitorTextWidget('random_pic', 'color:white;font-weight:bold', signals={'on-click':'signal'}) # No name here
|
||||
picture_widget = GenericMonitorPictureWidget('/tmp/cat2.jpg', name='NestedWidget', signals={'on-click':'signal'})
|
||||
popup = GenericMonitorPopup([url_widget, picture_widget])
|
||||
signals = {
|
||||
'on-click':'toggle-popup',
|
||||
# Could also use this behavior
|
||||
# Could also use this behavior [bugged since GNOME 42]
|
||||
# 'on-enter':'open-popup',
|
||||
# 'on-leave':'close-popup',
|
||||
'on-dblclick':'signal',
|
||||
@@ -68,7 +66,11 @@ class PicturePopup(GenericMonitor):
|
||||
self.imgs_idx += 1
|
||||
|
||||
def _forMe(self, sender):
|
||||
return sender == self.item.getFullName()
|
||||
return str(sender).endswith(self.item.getFullName())
|
||||
|
||||
def onClick(self, sender):
|
||||
if not self._forMe(sender): return
|
||||
print('Click from {}'.format(sender))
|
||||
|
||||
def _onScroll(self, sender):
|
||||
if not self._forMe(sender): return
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class TimerThread(Thread,GenericMonitor):
|
||||
self._stopLoop = False
|
||||
|
||||
self.textWidget = GenericMonitorTextWidget('')
|
||||
signals = {'on-click':'signal'}
|
||||
signals = {'on-click':'signal','on-dblclick':'signal','on-rightclick':'signal'}
|
||||
self.monitorItem = GenericMonitorItem('timer', [self.textWidget], signals, box='right')
|
||||
self.monitorGroup = GenericMonitorGroup('Timer', self.monitorItem)
|
||||
|
||||
|
||||
+381
-308
@@ -24,23 +24,22 @@
|
||||
https://github.com/bananenfisch/RecentItems/blob/master/extension.js
|
||||
https://github.com/julio641742/gnome-shell-extension-reference/blob/master/tutorials/POPUPMENU-EXTENSION.md
|
||||
https://gjs-docs.gnome.org/st10~1.0_api/st.widget
|
||||
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/panelMenu.js
|
||||
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/popupMenu.js
|
||||
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/panel.js
|
||||
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/panelMenu.js
|
||||
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/popupMenu.js
|
||||
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/panel.js
|
||||
*/
|
||||
|
||||
const St = imports.gi.St;
|
||||
const Gio = imports.gi.Gio;
|
||||
const Lang = imports.lang;
|
||||
const GLib = imports.gi.GLib
|
||||
const Main = imports.ui.main;
|
||||
const Mainloop = imports.mainloop;
|
||||
const Clutter = imports.gi.Clutter;
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
const PopupMenu = imports.ui.popupMenu;
|
||||
const GObject = imports.gi.GObject;
|
||||
const Pixbuf = imports.gi.GdkPixbuf;
|
||||
const Cogl = imports.gi.Cogl;
|
||||
import * as Extension from 'resource:///org/gnome/shell/extensions/extension.js';
|
||||
import St from 'gi://St';
|
||||
import Gio from 'gi://Gio';
|
||||
import GLib from 'gi://GLib';
|
||||
import Clutter from 'gi://Clutter';
|
||||
import GObject from 'gi://GObject';
|
||||
import Pixbuf from 'gi://GdkPixbuf';
|
||||
import Cogl from 'gi://Cogl';
|
||||
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||||
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
|
||||
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
|
||||
|
||||
|
||||
function hashGet(hash, key, defaultValue) {
|
||||
@@ -51,73 +50,25 @@ function hashGet(hash, key, defaultValue) {
|
||||
}
|
||||
|
||||
function log(message) {
|
||||
global.log('[GenericMontior]', message);
|
||||
console.error('[GenericMontior]', message);
|
||||
}
|
||||
|
||||
|
||||
var MyPopupMenuItem = GObject.registerClass({
|
||||
GTypeName: "MyPopupMenuItem"
|
||||
},
|
||||
class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
|
||||
_init(widgets, params) {
|
||||
super._init(params);
|
||||
class SignalMgt {
|
||||
|
||||
this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' });
|
||||
this.box.set_vertical(true);
|
||||
|
||||
for (let widgetIndex in widgets)
|
||||
this.box.add(widgets[widgetIndex]);
|
||||
|
||||
this.add_child(this.box);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var MonitorWidget = GObject.registerClass({
|
||||
GTypeName: "MonitorWidget"
|
||||
},
|
||||
class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
_init(item, group, dbus, position) {
|
||||
super._init(0.0);
|
||||
|
||||
this.name = item['name'];
|
||||
constructor(item, name, group, dbus, buttonMenu) {
|
||||
this.name = name;
|
||||
this.group = group;
|
||||
this.fullname = this.name + '@' + this.group;
|
||||
this.dbus = dbus;
|
||||
this.signals = {}
|
||||
this.buttonMenu = buttonMenu;
|
||||
this.signals = new WeakMap();
|
||||
this.widgets = new Array();
|
||||
this.timeouts = new Array();
|
||||
|
||||
if (item.hasOwnProperty('icon'))
|
||||
{
|
||||
if (typeof(item['icon']) === "string")
|
||||
this.icon = this._createIconOld(item);
|
||||
else
|
||||
this.icon = this._createIcon(item['icon']);
|
||||
if (this.icon !== null) {
|
||||
this._connectWidgetSignals(this.icon);
|
||||
this.add_child(this.icon);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.icon = null;
|
||||
|
||||
if (item.hasOwnProperty('text'))
|
||||
{
|
||||
if (typeof(item['text']) === "string")
|
||||
this.widget = this._createTextOld(item);
|
||||
else
|
||||
this.widget = this._createText(item['text']);
|
||||
|
||||
if (this.widget !== null) {
|
||||
this._connectWidgetSignals(this.widget);
|
||||
this.add_child(this.widget);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.widget = null;
|
||||
|
||||
if (item.hasOwnProperty('popup'))
|
||||
this._createPopup(item['popup']);
|
||||
this.menuOpen = false;
|
||||
this.nbClicks = 0;
|
||||
this.button = -1;
|
||||
|
||||
this.onClick = hashGet(item, 'on-click', '');
|
||||
this.onDblClick = hashGet(item, 'on-dblclick', '');
|
||||
@@ -126,199 +77,94 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
this.onEnter = hashGet(item, 'on-enter', '');
|
||||
this.onLeave = hashGet(item, 'on-leave', '');
|
||||
this.onScroll = hashGet(item, 'on-scroll', '');
|
||||
|
||||
let box = hashGet(item, 'box', 'center');
|
||||
|
||||
if (box === 'right' && position == -1)
|
||||
position = 0;
|
||||
|
||||
this.connect('style-changed', this._onStyleChanged.bind(this));
|
||||
|
||||
// Disable click event at PanelMenu.button level
|
||||
this.setSensitive(false);
|
||||
|
||||
this.nbClicks = 0;
|
||||
this.button = -1;
|
||||
|
||||
Main.panel.addToStatusArea(this.fullname, this, position, box);
|
||||
}
|
||||
|
||||
_onStyleChanged() {
|
||||
// Force these values to avoid big spaces between each widgets
|
||||
this._minHPadding = 1;
|
||||
this._natHPadding = 1;
|
||||
destroy() {
|
||||
for(let widgetIdx in this.widgets)
|
||||
this.disconnectWidgetSignals(this.widgets[widgetIdx]);
|
||||
for(let timeoutIdx in this.timeouts)
|
||||
GLib.Source.remove(this.timeouts[timeoutIdx]);
|
||||
}
|
||||
|
||||
updateSignals(item) {
|
||||
this.onClick = hashGet(item, 'on-click', this.onClick);
|
||||
this.onDblClick = hashGet(item, 'on-dblclick', this.onDblClick);
|
||||
this.onRightClick = hashGet(item, 'on-rightclick', this.onRightClick);
|
||||
this.onRightDblClick = hashGet(item, 'on-rightdblclick', this.onRightDblClick);
|
||||
this.onEnter = hashGet(item, 'on-enter', this.onEnter);
|
||||
this.onLeave = hashGet(item, 'on-leave', this.onLeave);
|
||||
this.onScroll = hashGet(item, 'on-scroll', this.onScroll);
|
||||
}
|
||||
|
||||
_connectWidgetSignals(widget) {
|
||||
this.signals[widget] = [];
|
||||
connectWidgetSignals(widget) {
|
||||
this.widgets.push(widget);
|
||||
let array = new Array();
|
||||
this.signals.set(widget, array);
|
||||
let id;
|
||||
id = widget.connect('enter-event', this._onEnter.bind(this));
|
||||
this.signals[widget].push(id);
|
||||
array.push(id);
|
||||
id = widget.connect('leave-event', this._onLeave.bind(this));
|
||||
this.signals[widget].push(id);
|
||||
array.push(id);
|
||||
id = widget.connect('scroll-event', this._onScroll.bind(this));
|
||||
this.signals[widget].push(id);
|
||||
array.push(id);
|
||||
widget.set_reactive(true);
|
||||
id = widget.connect('button-release-event', Lang.bind(this, this._clicked));
|
||||
this.signals[widget].push(id);
|
||||
id = widget.connect('button-release-event', this._clicked.bind(this));
|
||||
array.push(id);
|
||||
}
|
||||
|
||||
_disconnectWidgetSignals(widget) {
|
||||
for(let idx in this.signals[widget])
|
||||
widget.disconnect(this.signals[widget][idx]);
|
||||
this.signals[widget] = null;
|
||||
disconnectWidgetSignals(widget) {
|
||||
let array = this.signals.get(widget);
|
||||
for(let idx in array)
|
||||
widget.disconnect(array[idx]);
|
||||
this.signals.set(widget, null);
|
||||
}
|
||||
|
||||
toggleMenu() {
|
||||
if (this.menuOpen)
|
||||
{
|
||||
this.buttonMenu.menu.close();
|
||||
this.menuOpen = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.buttonMenu.menu.open(true);
|
||||
this.menuOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
_createPopup(item) {
|
||||
if (!item.hasOwnProperty('items')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let widgets = [];
|
||||
for (let itemIndex in item['items']) {
|
||||
let widget = null;
|
||||
let widgetDict = item['items'][itemIndex];
|
||||
|
||||
if (widgetDict.hasOwnProperty('text'))
|
||||
widget = this._createText(widgetDict['text']);
|
||||
else if (widgetDict.hasOwnProperty('picture'))
|
||||
widget = this._createPicture(widgetDict['picture']);
|
||||
|
||||
if (widget !== null)
|
||||
widgets.push(widget);
|
||||
}
|
||||
|
||||
if (widgets.length > 0) {
|
||||
this.menuItem = new MyPopupMenuItem(widgets, {});
|
||||
this.menu.addMenuItem(this.menuItem);
|
||||
this.menu.setSensitive(false);
|
||||
return this.menuItem;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
_createTextOld(item) {
|
||||
var itemValues = {};
|
||||
itemValues = { 'text':item['text'] };
|
||||
if (item.hasOwnProperty('style'))
|
||||
itemValues['style'] = item['style'];
|
||||
return this._createText(itemValues);
|
||||
}
|
||||
|
||||
_createText(item) {
|
||||
if (!item.hasOwnProperty('text')) {
|
||||
log("Text must have a 'text' value");
|
||||
return null;
|
||||
}
|
||||
|
||||
let style = hashGet(item, 'style', '');
|
||||
|
||||
this.textProperties = item;
|
||||
|
||||
if (item['text'] === '') {
|
||||
return null;
|
||||
} else {
|
||||
let widget = new St.Button({ label: item['text'] });
|
||||
widget.set_style(style);
|
||||
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
|
||||
_createIconOld(item) {
|
||||
var itemValues = {};
|
||||
itemValues = { 'path':item['icon'] };
|
||||
if (item.hasOwnProperty('iconStyle'))
|
||||
itemValues['style'] = item['iconStyle'];
|
||||
return this._createIcon(itemValues);
|
||||
}
|
||||
|
||||
_createIcon(item) {
|
||||
if (!item.hasOwnProperty('path')) {
|
||||
log("Icon must have a 'path' value");
|
||||
return null;
|
||||
}
|
||||
|
||||
let style = hashGet(item, 'style', '');
|
||||
|
||||
this.iconProperties = item;
|
||||
|
||||
if (item['path'] === '') {
|
||||
return null;
|
||||
} else {
|
||||
let gicon = Gio.icon_new_for_string(item['path']);
|
||||
gicon = new St.Icon({ gicon });
|
||||
gicon.set_style(style);
|
||||
|
||||
return gicon;
|
||||
}
|
||||
}
|
||||
|
||||
_createPicture(item) {
|
||||
if (!item.hasOwnProperty('path')) {
|
||||
log("Picture must have a 'path' value");
|
||||
return null;
|
||||
}
|
||||
|
||||
let width = hashGet(item, 'width', -1);
|
||||
let height = hashGet(item, 'height', -1);
|
||||
|
||||
if (typeof(width) === "string")
|
||||
width = parseInt(width, 10);
|
||||
|
||||
if (typeof(height) === "string")
|
||||
height = parseInt(height, 10);
|
||||
|
||||
let img = new Clutter.Image();
|
||||
let initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
|
||||
img.set_data(initialPixbuf.get_pixels(),
|
||||
initialPixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888
|
||||
: Cogl.PixelFormat.RGB_888,
|
||||
initialPixbuf.get_width(),
|
||||
initialPixbuf.get_height(),
|
||||
initialPixbuf.get_rowstride());
|
||||
let picture = new Clutter.Actor();
|
||||
picture.set_content(img);
|
||||
picture.set_size((width != -1)?width:initialPixbuf.get_width(),
|
||||
(height != -1)?height:initialPixbuf.get_height());
|
||||
|
||||
// Pack it in a box to avoid picture resize
|
||||
let box = new St.BoxLayout({});
|
||||
box.add_child(picture);
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
_manageEventAction(action, signalName) {
|
||||
if (action === 'open-popup')
|
||||
this.menu.open(true);
|
||||
{
|
||||
this.buttonMenu.menu.open(true);
|
||||
this.menuOpen = true;
|
||||
}
|
||||
else if (action === 'close-popup')
|
||||
this.menu.close();
|
||||
{
|
||||
this.buttonMenu.menu.close();
|
||||
this.menuOpen = false;
|
||||
}
|
||||
else if (action === 'toggle-popup')
|
||||
this.menu.toggle();
|
||||
else if (action == 'delete')
|
||||
{
|
||||
this.toggleMenu();
|
||||
}
|
||||
else if (action === 'delete')
|
||||
this.dbus.deleteItem(this, this.group);
|
||||
else if (action === 'signal')
|
||||
this.dbus.emitSignal(signalName, this.fullname);
|
||||
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
return Clutter.EVENT_STOP;
|
||||
}
|
||||
|
||||
_manageLeaveEvent() {
|
||||
this._manageEventAction(this.onLeave);
|
||||
}
|
||||
|
||||
|
||||
_doClickCallback() {
|
||||
let right = '';
|
||||
let nbClicks = '';
|
||||
|
||||
|
||||
if (this.button == 3)
|
||||
right = 'Right';
|
||||
if (this.nbClicks > 1)
|
||||
nbClicks = 'Dbl';
|
||||
|
||||
let signalName = 'on' + right + nbClicks + 'Click';
|
||||
const signalName = 'on' + right + nbClicks + 'Click';
|
||||
|
||||
let action = 'signal';
|
||||
switch(signalName) {
|
||||
@@ -343,8 +189,10 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
this.button = event.get_button();
|
||||
this.nbClicks = 1;
|
||||
|
||||
Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
|
||||
Lang.bind(this, this._doClickCallback));
|
||||
let sourceId = GLib.timeout_add(GLib.G_PRIORITY_DEFAULT,
|
||||
this.dbus.ClutterSettings['double-click-time'],
|
||||
this._doClickCallback.bind(this));
|
||||
this.timeouts.push(sourceId);
|
||||
}
|
||||
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
@@ -359,36 +207,112 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
}
|
||||
|
||||
_onScroll(actor, event) {
|
||||
let signalName = '';
|
||||
let direction = event.get_scroll_direction ();
|
||||
let signalName = '';
|
||||
const direction = event.get_scroll_direction ();
|
||||
if (direction == Clutter.ScrollDirection.UP)
|
||||
signalName = 'onScrollUp';
|
||||
else if (direction == Clutter.ScrollDirection.DOWN)
|
||||
signalName = 'onScrollDown';
|
||||
|
||||
return this._manageEventAction(this.onScroll, signalName);
|
||||
return this._manageEventAction(this.onScroll, signalName);
|
||||
}
|
||||
}
|
||||
|
||||
var MyPopupMenuItem = GObject.registerClass({
|
||||
GTypeName: 'MyPopupMenuItem'
|
||||
},
|
||||
class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
|
||||
_init(widgets, params) {
|
||||
super._init(params);
|
||||
|
||||
this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' });
|
||||
this.box.set_vertical(true);
|
||||
|
||||
for (let widgetIndex in widgets)
|
||||
this.box.add_child(widgets[widgetIndex]);
|
||||
|
||||
this.add_child(this.box);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var MonitorWidget = GObject.registerClass({
|
||||
GTypeName: 'MonitorWidget'
|
||||
},
|
||||
class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
_init(item, group, dbus, position) {
|
||||
super._init(0.0);
|
||||
|
||||
this.name = item['name'];
|
||||
this.group = group;
|
||||
this.fullname = this.name + '@' + this.group;
|
||||
this.dbus = dbus;
|
||||
this.menuItem = null;
|
||||
this.signalManager = new SignalMgt(item, this.name, group, dbus, this);
|
||||
this.popup_signals = null;
|
||||
this.popup_widgets = null;
|
||||
|
||||
if (item.hasOwnProperty('icon'))
|
||||
{
|
||||
if (typeof(item['icon']) === 'string')
|
||||
this.icon = this._createIconOld(item);
|
||||
else
|
||||
this.icon = this._createIcon(item['icon']);
|
||||
if (this.icon !== null) {
|
||||
this.signalManager.connectWidgetSignals(this.icon);
|
||||
this.add_child(this.icon);
|
||||
}
|
||||
} else
|
||||
this.icon = null;
|
||||
|
||||
if (item.hasOwnProperty('text'))
|
||||
{
|
||||
if (typeof(item['text']) === 'string')
|
||||
this.widget = this._createTextOld(item);
|
||||
else
|
||||
this.widget = this._createText(item['text']);
|
||||
|
||||
if (this.widget !== null) {
|
||||
this.signalManager.connectWidgetSignals(this.widget);
|
||||
this.add_child(this.widget);
|
||||
}
|
||||
} else
|
||||
this.widget = null;
|
||||
|
||||
if (item.hasOwnProperty('popup'))
|
||||
this._createPopup(item['popup']);
|
||||
|
||||
const box = hashGet(item, 'box', 'center');
|
||||
|
||||
if (box === 'right' && position == -1)
|
||||
position = 0;
|
||||
|
||||
this.connect('style-changed', this._onStyleChanged.bind(this));
|
||||
|
||||
Main.panel.addToStatusArea(this.fullname, this, position, box);
|
||||
}
|
||||
|
||||
update(item) {
|
||||
let prevWidget = this.widget;
|
||||
let prevIcon = this.icon;
|
||||
const prevWidget = this.widget;
|
||||
const prevIcon = this.icon;
|
||||
|
||||
if (item.hasOwnProperty('text'))
|
||||
{
|
||||
let text = '';
|
||||
let style = '';
|
||||
if (typeof(item['text']) === "string") {
|
||||
if (typeof(item['text']) === 'string') {
|
||||
text = hashGet(item, 'text', '');
|
||||
style = hashGet(item, 'style', '');
|
||||
} else {
|
||||
let textValues = item['text'];
|
||||
const textValues = item['text'];
|
||||
text = hashGet(textValues, 'text', '');
|
||||
style = hashGet(textValues, 'style', '');
|
||||
}
|
||||
|
||||
if (text !== '') {
|
||||
if (!this.widget) {
|
||||
if (typeof(item['text']) === "string")
|
||||
if (typeof(item['text']) === 'string')
|
||||
this.widget = this._createTextOld(item);
|
||||
else
|
||||
this.widget = this._createText(item['text']);
|
||||
@@ -407,24 +331,24 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
{
|
||||
let icon = '';
|
||||
let style = '';
|
||||
if (typeof(item['icon']) === "string") {
|
||||
if (typeof(item['icon']) === 'string') {
|
||||
icon = hashGet(item, 'icon', '');
|
||||
style = hashGet(item, 'iconStyle', '');
|
||||
} else {
|
||||
let iconValues = item['icon'];
|
||||
const iconValues = item['icon'];
|
||||
icon = hashGet(iconValues, 'path', '');
|
||||
style = hashGet(iconValues, 'style', '');
|
||||
}
|
||||
|
||||
if (icon !== '') {
|
||||
if (typeof(item['icon']) === "string")
|
||||
if (typeof(item['icon']) === 'string')
|
||||
this.icon = this._createIconOld(item);
|
||||
else
|
||||
this.icon = this._createIcon(item['icon']);
|
||||
}
|
||||
|
||||
if (prevIcon) {
|
||||
this._disconnectWidgetSignals(prevIcon);
|
||||
this.signalManager.disconnectWidgetSignals(prevIcon);
|
||||
this.insert_child_above(this.icon, prevIcon);
|
||||
this.remove_child(prevIcon);
|
||||
//delete prevIcon;
|
||||
@@ -438,26 +362,22 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
if (item.hasOwnProperty('popup'))
|
||||
{
|
||||
let menuOpen = this.menu.isOpen;
|
||||
const menuOpen = this.menu.isOpen;
|
||||
if (this.menuItem) {
|
||||
if (menuOpen)
|
||||
this.menu.close();
|
||||
for(let widgetIdx in this.popup_widgets)
|
||||
this.signalManager.disconnectWidgetSignals(this.popup_widgets[widgetIdx]);
|
||||
this.menu.removeAll();
|
||||
//delete this.menuItem;
|
||||
}
|
||||
|
||||
let popup = this._createPopup(item['popup']);
|
||||
const popup = this._createPopup(item['popup']);
|
||||
if (popup !== null && menuOpen)
|
||||
this.menu.open(true);
|
||||
}
|
||||
|
||||
this.onClick = hashGet(item, 'on-click', this.onClick);
|
||||
this.onDblClick = hashGet(item, 'on-dblclick', this.onDblClick);
|
||||
this.onRightClick = hashGet(item, 'on-rightclick', this.onRightClick);
|
||||
this.onRightDblClick = hashGet(item, 'on-rightdblclick', this.onRightDblClick);
|
||||
this.onEnter = hashGet(item, 'on-enter', this.onEnter);
|
||||
this.onLeave = hashGet(item, 'on-leave', this.onLeave);
|
||||
this.onScroll = hashGet(item, 'on-scroll', this.onScroll);
|
||||
this.signalManager.updateSignals(item);
|
||||
}
|
||||
|
||||
openPopup() {
|
||||
@@ -474,20 +394,175 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
destroy() {
|
||||
this.menu.close();
|
||||
this.signalManager.destroy();
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
_onStyleChanged() {
|
||||
// Force these values to avoid big spaces between each widgets
|
||||
this._minHPadding = 1;
|
||||
this._natHPadding = 1;
|
||||
}
|
||||
|
||||
_createPopup(item) {
|
||||
if (!item.hasOwnProperty('items')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let widgets = [];
|
||||
this.popup_signals = new WeakMap();
|
||||
this.popup_widgets = new Array();
|
||||
for (let itemIndex in item['items']) {
|
||||
let widget = null;
|
||||
let widgetDict = item['items'][itemIndex];
|
||||
|
||||
let nestedItem = null;
|
||||
if (widgetDict.hasOwnProperty('text')) {
|
||||
nestedItem = widgetDict['text'];
|
||||
widget = this._createLabel(nestedItem);
|
||||
} else if (widgetDict.hasOwnProperty('picture')) {
|
||||
nestedItem = widgetDict['picture'];
|
||||
widget = this._createPicture(nestedItem);
|
||||
} else {
|
||||
log('No known widget defined in popup');
|
||||
}
|
||||
|
||||
if (nestedItem === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
widgets.push(widget);
|
||||
const name = hashGet(nestedItem, 'name', '');
|
||||
this.popup_signals[widget] = new SignalMgt(nestedItem, name,
|
||||
this.fullname, this.dbus,
|
||||
this);
|
||||
this.popup_signals[widget].connectWidgetSignals(widget);
|
||||
this.popup_widgets.push(widget);
|
||||
}
|
||||
|
||||
if (widgets.length > 0) {
|
||||
this.menuItem = new MyPopupMenuItem(widgets, {});
|
||||
this.menu.addMenuItem(this.menuItem);
|
||||
this.menu.setSensitive(false);
|
||||
return this.menuItem;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
_createTextOld(item) {
|
||||
var itemValues = {};
|
||||
itemValues = { 'text':item['text'] };
|
||||
if (item.hasOwnProperty('style'))
|
||||
itemValues['style'] = item['style'];
|
||||
return this._createText(itemValues);
|
||||
}
|
||||
|
||||
__createText(item, isLabel) {
|
||||
if (!item.hasOwnProperty('text')) {
|
||||
log('Text must have a \'text\' value');
|
||||
return null;
|
||||
}
|
||||
|
||||
const style = hashGet(item, 'style', '');
|
||||
|
||||
this.textProperties = item;
|
||||
|
||||
if (item['text'] === '') {
|
||||
return null;
|
||||
} else {
|
||||
let widget = null;
|
||||
if (isLabel)
|
||||
widget = new St.Label({ text: item['text'] });
|
||||
else
|
||||
widget = new St.Button({ label: item['text'] });
|
||||
widget.set_style(style);
|
||||
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
|
||||
_createText(item) {
|
||||
return this.__createText(item, false);
|
||||
}
|
||||
|
||||
_createLabel(item) {
|
||||
return this.__createText(item, true);
|
||||
}
|
||||
|
||||
_createIconOld(item) {
|
||||
var itemValues = {};
|
||||
itemValues = { 'path':item['icon'] };
|
||||
if (item.hasOwnProperty('iconStyle'))
|
||||
itemValues['style'] = item['iconStyle'];
|
||||
return this._createIcon(itemValues);
|
||||
}
|
||||
|
||||
_createIcon(item) {
|
||||
if (!item.hasOwnProperty('path')) {
|
||||
log('Icon must have a \'path\' value');
|
||||
return null;
|
||||
}
|
||||
|
||||
const style = hashGet(item, 'style', '');
|
||||
|
||||
this.iconProperties = item;
|
||||
|
||||
if (item['path'] === '') {
|
||||
return null;
|
||||
} else {
|
||||
let gicon = Gio.icon_new_for_string(item['path']);
|
||||
gicon = new St.Icon({ gicon });
|
||||
gicon.set_style(style);
|
||||
|
||||
return gicon;
|
||||
}
|
||||
}
|
||||
|
||||
_createPicture(item) {
|
||||
if (!item.hasOwnProperty('path')) {
|
||||
log('Picture must have a \'path\' value');
|
||||
return null;
|
||||
}
|
||||
|
||||
let width = hashGet(item, 'width', -1);
|
||||
let height = hashGet(item, 'height', -1);
|
||||
|
||||
if (typeof(width) === 'string')
|
||||
width = parseInt(width, 10);
|
||||
|
||||
if (typeof(height) === 'string')
|
||||
height = parseInt(height, 10);
|
||||
|
||||
const img = new Clutter.Image();
|
||||
const initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
|
||||
img.set_data(initialPixbuf.get_pixels(),
|
||||
initialPixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888
|
||||
: Cogl.PixelFormat.RGB_888,
|
||||
initialPixbuf.get_width(),
|
||||
initialPixbuf.get_height(),
|
||||
initialPixbuf.get_rowstride());
|
||||
const picture = new Clutter.Actor();
|
||||
picture.set_content(img);
|
||||
picture.set_size((width != -1)?width:initialPixbuf.get_width(),
|
||||
(height != -1)?height:initialPixbuf.get_height());
|
||||
|
||||
// Pack it in a box to avoid picture resize
|
||||
const box = new St.BoxLayout({});
|
||||
box.add_child(picture);
|
||||
|
||||
return box;
|
||||
}
|
||||
});
|
||||
|
||||
// From https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/interfaces.js
|
||||
// loads a xml file into an in-memory string
|
||||
function loadInterfaceXml(filename) {
|
||||
let extension = imports.misc.extensionUtils.getCurrentExtension();
|
||||
function loadInterfaceXml(extension, filename) {
|
||||
const interfacesDir = extension.dir.get_child('.');
|
||||
|
||||
let interfacesDir = extension.dir.get_child('.');
|
||||
const file = interfacesDir.get_child(filename);
|
||||
|
||||
let file = interfacesDir.get_child(filename);
|
||||
|
||||
let [result, contents] = imports.gi.GLib.file_get_contents(file.get_path());
|
||||
let [result, contents] = GLib.file_get_contents(file.get_path());
|
||||
|
||||
if (result) {
|
||||
// HACK: The "" + trick is important as hell because file_get_contents returns
|
||||
@@ -496,8 +571,11 @@ function loadInterfaceXml(filename) {
|
||||
// is no `XML` on very recent SpiderMonkey releases (or, if SpiderMonkey is old enough,
|
||||
// will spit out a TypeError soon).
|
||||
if (contents instanceof Uint8Array)
|
||||
contents = imports.byteArray.toString(contents);
|
||||
let res = `<node>${contents}</node>`;
|
||||
{
|
||||
const decoder = new TextDecoder();
|
||||
contents = decoder.decode(contents);
|
||||
}
|
||||
const res = `<node>${contents}</node>`;
|
||||
return res;
|
||||
} else {
|
||||
throw new Error(`Generic monitor: Could not load file: ${filename}`);
|
||||
@@ -505,11 +583,11 @@ function loadInterfaceXml(filename) {
|
||||
}
|
||||
|
||||
class GenericMonitorDBUS {
|
||||
constructor() {
|
||||
constructor(extension) {
|
||||
this.monitor_groups = {};
|
||||
this.actor_clicked = {};
|
||||
this.ClutterSettings = Clutter.Settings.get_default();
|
||||
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml('dbus.xml'), this);
|
||||
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml(extension, 'dbus.xml'), this);
|
||||
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
|
||||
this._dbusImpl.emit_signal('onActivate', null);
|
||||
}
|
||||
@@ -530,7 +608,7 @@ class GenericMonitorDBUS {
|
||||
}
|
||||
|
||||
for (let itemIndex in parameters['items']) {
|
||||
let item = parameters['items'][itemIndex];
|
||||
const item = parameters['items'][itemIndex];
|
||||
if (!item.hasOwnProperty('name')) {
|
||||
log('No name defined for item');
|
||||
return false;
|
||||
@@ -542,7 +620,7 @@ class GenericMonitorDBUS {
|
||||
|
||||
_getItemFromGroup(group, name) {
|
||||
for (let groupItemIndex in group) {
|
||||
let groupItem = group[groupItemIndex];
|
||||
const groupItem = group[groupItemIndex];
|
||||
if (groupItem.name === name)
|
||||
return groupItem;
|
||||
}
|
||||
@@ -551,7 +629,7 @@ class GenericMonitorDBUS {
|
||||
}
|
||||
|
||||
_getItemFromFullName(fullname) {
|
||||
let splitName = fullname.split('@');
|
||||
const splitName = fullname.split('@');
|
||||
if (splitName.length !== 2) {
|
||||
log(`Invalid name ${fullname}`);
|
||||
return null;
|
||||
@@ -574,11 +652,11 @@ class GenericMonitorDBUS {
|
||||
}
|
||||
|
||||
notify(str) {
|
||||
let parameters = JSON.parse(str);
|
||||
const parameters = JSON.parse(str);
|
||||
if (!this._checkParameters(parameters))
|
||||
return;
|
||||
|
||||
let groupName = parameters['group'];
|
||||
const groupName = parameters['group'];
|
||||
let group;
|
||||
if (!this.monitor_groups.hasOwnProperty(groupName)) {
|
||||
group = [];
|
||||
@@ -588,7 +666,7 @@ class GenericMonitorDBUS {
|
||||
}
|
||||
|
||||
for (let itemIndex in parameters['items']) {
|
||||
let item = parameters['items'][itemIndex];
|
||||
const item = parameters['items'][itemIndex];
|
||||
let monitorWidget = this._getItemFromGroup(group, item['name']);
|
||||
|
||||
// New widget
|
||||
@@ -596,8 +674,8 @@ class GenericMonitorDBUS {
|
||||
let position = group.length - 1;
|
||||
// Find real position
|
||||
if (position != -1) {
|
||||
let lastWidget = group[position].container;
|
||||
let childrens = lastWidget.get_parent().get_children();
|
||||
const lastWidget = group[position].container;
|
||||
const childrens = lastWidget.get_parent().get_children();
|
||||
for(;position < childrens.length; position++)
|
||||
{
|
||||
if (childrens[position] == lastWidget) {
|
||||
@@ -627,7 +705,7 @@ class GenericMonitorDBUS {
|
||||
}
|
||||
|
||||
deleteItems(str) {
|
||||
let parameters = JSON.parse(str);
|
||||
const parameters = JSON.parse(str);
|
||||
|
||||
if (!parameters.hasOwnProperty('items')) {
|
||||
log('No items defined');
|
||||
@@ -636,7 +714,7 @@ class GenericMonitorDBUS {
|
||||
|
||||
for (let itemIndex in parameters['items']) {
|
||||
let itemName = parameters['items'][itemIndex];
|
||||
let splitName = itemName.split('@');
|
||||
const splitName = itemName.split('@');
|
||||
if (splitName.length !== 2) {
|
||||
log(`Invalid name ${itemName}`);
|
||||
return false;
|
||||
@@ -654,7 +732,7 @@ class GenericMonitorDBUS {
|
||||
}
|
||||
|
||||
deleteGroups(str) {
|
||||
let parameters = JSON.parse(str);
|
||||
const parameters = JSON.parse(str);
|
||||
|
||||
if (!parameters.hasOwnProperty('groups')) {
|
||||
log('No groups defined');
|
||||
@@ -663,29 +741,29 @@ class GenericMonitorDBUS {
|
||||
|
||||
let groupsToDelete = [];
|
||||
for (let groupIndex in parameters['groups']) {
|
||||
let groupName = parameters['groups'][groupIndex];
|
||||
const groupName = parameters['groups'][groupIndex];
|
||||
if (!this.monitor_groups.hasOwnProperty(groupName))
|
||||
continue;
|
||||
let group = this.monitor_groups[groupName];
|
||||
const group = this.monitor_groups[groupName];
|
||||
for (let itemIndex in group)
|
||||
group[itemIndex].destroy();
|
||||
groupsToDelete.push(groupName);
|
||||
}
|
||||
for (let groupDeleteIndex in groupsToDelete) {
|
||||
let groupName = groupsToDelete[groupDeleteIndex];
|
||||
const groupName = groupsToDelete[groupDeleteIndex];
|
||||
delete this.monitor_groups[groupName];
|
||||
}
|
||||
}
|
||||
|
||||
_popupFunction(str) {
|
||||
let parameters = JSON.parse(str);
|
||||
const parameters = JSON.parse(str);
|
||||
|
||||
if (!parameters.hasOwnProperty('item')) {
|
||||
log('No item defined');
|
||||
return false;
|
||||
}
|
||||
|
||||
let monitorWidget = this._getItemFromFullName(parameters['item']);
|
||||
const monitorWidget = this._getItemFromFullName(parameters['item']);
|
||||
if (monitorWidget !== null)
|
||||
return monitorWidget;
|
||||
else
|
||||
@@ -695,27 +773,27 @@ class GenericMonitorDBUS {
|
||||
}
|
||||
|
||||
openPopup(str) {
|
||||
let monitorWidget = this._popupFunction(str)
|
||||
const monitorWidget = this._popupFunction(str)
|
||||
if (monitorWidget !== null)
|
||||
monitorWidget.openPopup();
|
||||
}
|
||||
|
||||
closePopup(str) {
|
||||
let monitorWidget = this._popupFunction(str)
|
||||
const monitorWidget = this._popupFunction(str)
|
||||
if (monitorWidget !== null)
|
||||
monitorWidget.closePopup();
|
||||
}
|
||||
|
||||
togglePopup(str) {
|
||||
let monitorWidget = this._popupFunction(str)
|
||||
const monitorWidget = this._popupFunction(str)
|
||||
if (monitorWidget !== null)
|
||||
monitorWidget.togglePopup();
|
||||
}
|
||||
|
||||
destructor() {
|
||||
destroy() {
|
||||
this._dbusImpl.emit_signal('onDeactivate', null);
|
||||
for (let groupIndex in this.monitor_groups) {
|
||||
let group = this.monitor_groups[groupIndex];
|
||||
const group = this.monitor_groups[groupIndex];
|
||||
for (let itemIndex in group)
|
||||
group[itemIndex].destroy();
|
||||
}
|
||||
@@ -724,26 +802,21 @@ class GenericMonitorDBUS {
|
||||
}
|
||||
}
|
||||
|
||||
class Extension {
|
||||
export default class GenericMonitorExtension extends Extension.Extension {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.textDBusService = null;
|
||||
}
|
||||
|
||||
enable() {
|
||||
this.textDBusService = new GenericMonitorDBUS();
|
||||
this.textDBusService = new GenericMonitorDBUS(this);
|
||||
}
|
||||
|
||||
disable() {
|
||||
this.textDBusService.destructor();
|
||||
delete this.textDBusService;
|
||||
if (this.textDBusService !== null) {
|
||||
this.textDBusService.destroy();
|
||||
delete this.textDBusService;
|
||||
this.textDBusService = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let extension = new Extension();
|
||||
|
||||
function init() {
|
||||
}
|
||||
|
||||
function enable() {
|
||||
extension.enable();
|
||||
}
|
||||
|
||||
function disable() {
|
||||
extension.disable();
|
||||
}
|
||||
|
||||
+5
-5
@@ -2,11 +2,11 @@
|
||||
"uuid": "generic-monitor@gnome-shell-extensions",
|
||||
"name": "Generic Monitor",
|
||||
"description": "Display text & icon on systray using DBUS",
|
||||
"version": "3",
|
||||
"version": "15",
|
||||
"shell-version": [
|
||||
"3.38",
|
||||
"3.36",
|
||||
"3.34"
|
||||
"47",
|
||||
"46",
|
||||
"45"
|
||||
],
|
||||
"url": "http://indefero.soutade.fr/p/genericmonitor"
|
||||
"url": "https://forge.soutade.fr/soutade/GnomeShellGenericMonitor"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user