Skip to content

Commit

Permalink
Manually merged (master) pull requests #61, #67, #77, #81, #85 and #87
Browse files Browse the repository at this point in the history
…with branch pygi-python3.
  • Loading branch information
m7s@bastu.net committed Dec 28, 2019
1 parent 80e2550 commit e7b8fb9
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Theming HOWTO
Expand Up @@ -61,7 +61,7 @@ Here is a <colors></colors> section containing all the default values used by do
<colors>
<color1 name="Popup background" default="#333333" opacity="80" />
<color2 name="Normal text" default="#FFFFFF" opacity="no" />
<color3 name="Active window" text default="#FFFF75" opacity="no" />
<color3 name="Active window text" text default="#FFFF75" opacity="no" />
<color4 name="Minimized window text" default="#9C9C9C" opacity="no" />
<color5 name="Active color" default="#FFFF75" opacity="63" />
<color6 name="Not used" default="#000000" opacity="no" />
Expand Down
10 changes: 5 additions & 5 deletions dbx_preference
Expand Up @@ -1440,12 +1440,12 @@ class PrefDialog():

def __find_themes(self):
# Reads the themes from /usr/share/dockbarx/themes and
# ~/.dockbarx/themes and returns a dict of the theme names
# and paths so that a theme can be loaded.
# ${XDG_DATA_HOME:-$HOME/.local/share}/dockbarx/themes
# and returns a dict of the theme names and paths so
# that a theme can be loaded.
themes = {}
theme_paths = []
homeFolder = os.path.expanduser("~")
theme_folder = homeFolder + "/.dockbarx/themes"
theme_folder = os.path.join(get_app_homedir(), "themes")
dirs = ["/usr/share/dockbarx/themes", theme_folder]
for dir in dirs:
if os.path.exists(dir) and os.path.isdir(dir):
Expand All @@ -1463,7 +1463,7 @@ class PrefDialog():
name = str(name)
themes[name] = theme_path
if not themes:
message = _("No working themes found in /usr/share/dockbarx/themes or ~/.dockbarx/themes")
message = _("No working themes found in /usr/share/dockbarx/themes or ~/.local/share/dockbarx/themes")
flags = Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT
md = Gtk.MessageDialog(self.dialog,
flags,
Expand Down
12 changes: 7 additions & 5 deletions dockbarx/applets.py
Expand Up @@ -26,6 +26,7 @@
from gi.repository import GObject
from dbus.mainloop.glib import DBusGMainLoop
from .log import logger
from .common import get_app_homedir



Expand All @@ -37,13 +38,14 @@ def __init__(self):
self.find_applets()

def find_applets(self):
# Reads the themes from /usr/share/dockbarx/themes/dock_themes and
# ~/.dockbarx/themes/dock_themes and returns a dict
# of the theme file names and paths so that a theme can be loaded
# Reads the applets from /usr/share/dockbarx/applets and
# ${XDG_DATA_HOME:-$HOME/.local/share}/dockbarx/applets
# and returns a dict of the applets file names and paths so that a
# applet can be loaded.
self.applets = {}
home_folder = os.path.expanduser("~")
theme_folder = home_folder + "/.dockbarx/applets"
dirs = ["/usr/share/dockbarx/applets", theme_folder]
applets_folder = os.path.join(get_app_homedir(), "applets")
dirs = ["/usr/share/dockbarx/applets", applets_folder]
for dir in dirs:
if not(os.path.exists(dir) and os.path.isdir(dir)):
continue
Expand Down
28 changes: 28 additions & 0 deletions dockbarx/common.py
Expand Up @@ -30,6 +30,7 @@
import weakref
import locale
from .log import logger
import sys
import struct


Expand Down Expand Up @@ -72,6 +73,33 @@ def check_program(name):
for dir in os.environ['PATH'].split(':'):
prog = os.path.join(dir, name)
if os.path.exists(prog): return prog


def get_app_homedir():
homedir = os.environ['HOME']
default = os.path.join(homedir, '.local', 'share')
appdir = os.path.join(
os.getenv('XDG_DATA_HOME', default),
'dockbarx'
)
"""
Migration Path
From "$HOME/.dockbarx" to "${XDG_DATA_HOME:-$HOME/.local/share}/dockbarx"
"""
old_appdir = os.path.join(homedir, '.dockbarx')
if os.path.exists(old_appdir) and os.path.isdir(old_appdir):
try:
os.rename(old_appdir, appdir)
except OSError:
sys.stderr.write(
"Could not move dir '%s' to '%s'. Move the contents of '%s' to '%s' manually and then remove the first location.\n"
% (old_appdir, appdir, old_appdir, appdir)
)
"""
End Migration Path
"""
return appdir


class Connector():
"""A class to simplify disconnecting of signals"""
Expand Down
27 changes: 13 additions & 14 deletions dockbarx/dockbar.py
Expand Up @@ -947,22 +947,22 @@ def __add_window(self, window):
window = Wnck.Window.get(window.get_xid())
res_class = window.get_class_group().get_res_class().lower()
res_name = window.get_class_group().get_name().lower()
if window.has_name():
fallback = window.get_name().lower()
else:
#in case window has no name - issue with Spotify
pid = window.get_pid()
try:
f = open("/proc/"+str(pid)+"/cmdline", "r")
except:
pass
identifier = res_class or res_name
if not identifier:
if window.has_name():
identifier = window.get_name().lower()
else:
#in case window has no name - issue with Spotify
pid = window.get_pid()
try:
f = open("/proc/"+str(pid)+"/cmdline", "r")
except:
raise
cmd = f.readline().split("\0")[0]
if "/" in cmd:
fallback = cmd.split("/")[-1]
identifier = cmd.split("/")[-1]
else:
fallback = cmd
identifier = res_class or res_name or fallback
identifier = cmd
# Special cases
if identifier in SPECIAL_RES_CLASSES:
identifier = SPECIAL_RES_CLASSES[identifier]
Expand Down Expand Up @@ -1363,8 +1363,7 @@ def change_identifier(self, path=None, old_identifier=None):
self.__add_window(window)

def edit_launcher(self, path, identifier):
launcher_dir = os.path.join(os.path.expanduser("~"),
".dockbarx", "launchers")
launcher_dir = os.path.join(get_app_homedir(), "launchers")
if not os.path.exists(launcher_dir):
os.makedirs(launcher_dir)
if path:
Expand Down
7 changes: 7 additions & 0 deletions dockbarx/groupbutton.py
Expand Up @@ -374,6 +374,7 @@ def add_window(self, wnck_window):
self.update_name()
class_group = window.wnck.get_class_group()
self.button.icon_factory.set_class_group(class_group)
class_group.connect("icon-changed", self.group_icon_changed)
if self.button.launch_effect:
self.button.remove_launch_effect()
if window.needs_attention:
Expand Down Expand Up @@ -471,6 +472,12 @@ def window_desktop_changed(self):
self.locked_popup.resize(10, 10)
self.locked_popup.show()

def group_icon_changed(self, class_group):
self.button.icon_factory.reset_icon()
self.button.icon_factory.reset_surfaces()
self.button.update_state(force_update=True)
self.button.drag_source_set_icon_pixbuf(self.button.icon_factory.get_icon(32))


#### Opacify
def opacify(self, delay=0):
Expand Down
7 changes: 6 additions & 1 deletion dockbarx/iconfactory.py
Expand Up @@ -131,6 +131,11 @@ def get_size(self):

def get_icon(self, size):
return self.__find_icon_pixbuf(size)


def reset_icon(self):
self.icon = None


def reset_surfaces(self, arg=None):
self.surfaces = {}
Expand Down Expand Up @@ -707,7 +712,7 @@ def __command_transp_sat(self, surface, opacity="100", saturation="100"):
alpha = self.__get_alpha(opacity)
# Todo: Add error check for saturation
sat = float(saturation)
if sat < 100:
if sat != 100:
im = self.__surface2pil(surface)
w, h = im.size
pixels = im.load()
Expand Down
30 changes: 29 additions & 1 deletion dockbarx/log.py
Expand Up @@ -20,12 +20,40 @@
import logging
import logging.handlers
import os
import sys


logging.basicConfig(format="%(message)s", level=logging.DEBUG)
logger = logging.getLogger("DockbarX")

def get_app_homedir():
homedir = os.environ['HOME']
default = os.path.join(homedir, '.local', 'share')
appdir = os.path.join(
os.getenv('XDG_DATA_HOME', default),
'dockbarx'
)
"""
Migration Path
From "$HOME/.dockbarx" to "${XDG_DATA_HOME:-$HOME/.local/share}/dockbarx"
"""
old_appdir = os.path.join(homedir, '.dockbarx')
if os.path.exists(old_appdir) and os.path.isdir(old_appdir):
try:
os.rename(old_appdir, appdir)
except OSError:
sys.stderr.write(
"Could not move dir '%s' to '%s'. Move the contents of '%s' to '%s' manually and then remove the first location.\n"
% (old_appdir, appdir, old_appdir, appdir)
)
"""
End Migration Path
"""
return appdir


def log_to_file():
log_dir = os.path.join(os.path.expanduser("~"), ".dockbarx", "log")
log_dir = os.path.join(get_app_homedir(), "log")
if not os.path.exists(log_dir):
os.makedirs(log_dir)
log_file = os.path.join(log_dir, "dockbarx.log")
Expand Down
35 changes: 17 additions & 18 deletions dockbarx/theme.py
Expand Up @@ -27,6 +27,7 @@
import array
from .common import ODict
from .common import Globals
from .common import get_app_homedir
from .log import logger
from PIL import Image

Expand Down Expand Up @@ -147,12 +148,13 @@ def on_theme_changed(self, arg=None):

def find_themes(self):
# Reads the themes from /usr/share/dockbarx/themes and
# ~/.dockbarx/themes and returns a dict
# of the theme names and paths so that a theme can be loaded
# ${XDG_DATA_HOME:-$HOME/.local/share}/dockbarx/themes
# and returns a dict of the theme names and paths so
# that a theme can be loaded.
themes = {}
theme_paths = []
homeFolder = os.path.expanduser("~")
theme_folder = homeFolder + "/.dockbarx/themes"
theme_folder = os.path.join(get_app_homedir(), "themes")
dirs = ["/usr/share/dockbarx/themes", theme_folder]
for dir in dirs:
if os.path.exists(dir) and os.path.isdir(dir):
Expand All @@ -172,11 +174,10 @@ def find_themes(self):
md = Gtk.MessageDialog(None,
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE,
_("No working themes found in /usr/share/dockbarx/themes or ~/.dockbarx/themes"))
_("No working themes found in /usr/share/dockbarx/themes or ~/.local/share/dockbarx/themes"))
md.run()
md.destroy()
raise NoThemesError("No working themes found in " + \
"/usr/share/dockbarx/themes or ~/.dockbarx/themes")
raise NoThemesError("No working themes found in /usr/share/dockbarx/themes or ${XDG_DATA_HOME:-$HOME/.local/share}/.dockbarx/themes")
return themes

def reload(self):
Expand Down Expand Up @@ -407,12 +408,12 @@ def get(self, key, default=None):

def find_styles(self):
# Reads the styles from /usr/share/dockbarx/themes/popup_styles and
# ~/.dockbarx/themes/popup_styles and returns a dict
# of the style file names and paths so that a style can be loaded
# ${XDG_DATA_HOME:-$HOME/.local/share}/dockbarx/themes/popup_styles
# and returns a dict of the style file names and paths so that a
# style can be loaded
styles = {}
style_paths = []
homeFolder = os.path.expanduser("~")
style_folder = homeFolder + "/.dockbarx/themes/popup_styles"
style_folder = os.path.join(get_app_homedir(), "themes", "popup_styles")
dirs = ["/usr/share/dockbarx/themes/popup_styles", style_folder]
for dir in dirs:
if os.path.exists(dir) and os.path.isdir(dir):
Expand Down Expand Up @@ -523,8 +524,7 @@ def get_styles(self, theme_name=None):
# For DockbarX preference. This function makes a dict of the names and
# file names of the styles for all styles that can be opened correctly.
styles = {}
home_folder = os.path.expanduser("~")
style_folder = home_folder + "/.dockbarx/themes/popup_styles"
style_folder = os.path.join(get_app_homedir(), "themes", "popup_styles")
dirs = ["/usr/share/dockbarx/themes/popup_styles", style_folder]
for dir in dirs:
if os.path.exists(dir) and os.path.isdir(dir):
Expand Down Expand Up @@ -615,12 +615,12 @@ def get_bg(self, bar, size=None):

def find_themes(self):
# Reads the themes from /usr/share/dockbarx/themes/dock_themes and
# ~/.dockbarx/themes/dock_themes and returns a dict
# of the theme file names and paths so that a theme can be loaded
# ${XDG_DATA_HOME:-$HOME/.local/share}/dockbarx/themes
# and returns a dict of the theme names and paths so
# that a theme can be loaded.
themes = {}
theme_paths = []
homeFolder = os.path.expanduser("~")
theme_folder = homeFolder + "/.dockbarx/themes/dock"
theme_folder = os.path.join(get_app_homedir(), "themes")
dirs = ["/usr/share/dockbarx/themes/dock", theme_folder]
for dir in dirs:
if os.path.exists(dir) and os.path.isdir(dir):
Expand Down Expand Up @@ -737,8 +737,7 @@ def get_themes(self):
# For DockbarX preference. This function makes a dict of the names and
# file names of the themes for all themes that can be opened correctly.
themes = {}
home_folder = os.path.expanduser("~")
theme_folder = home_folder + "/.dockbarx/themes/dock"
theme_folder = os.path.join(get_app_homedir(), "themes", "dock")
dirs = ["/usr/share/dockbarx/themes/dock", theme_folder]
for dir in dirs:
if os.path.exists(dir) and os.path.isdir(dir):
Expand Down
16 changes: 0 additions & 16 deletions dockx
Expand Up @@ -783,28 +783,12 @@ class DockX(CairoDockX):
mx, my, mw, mh = mr.x, mr.y, mr.width, mr.height
if self.globals.settings["dock/position"] == "left":
strut = [x + w, 0, 0, 0, y, y + h - 1, 0, 0, 0, 0, 0, 0]
# Make sure that there's no monitor on the left side of this one.
if s.get_monitor_at_point(mx - 5, y + h // 2) != self.monitor:
set_strut = False
elif self.globals.settings["dock/position"] == "right":
strut = [0, sw - x, 0, 0, 0, 0, y, y + h - 1, 0, 0, 0, 0]
if s.get_monitor_at_point(mx + mw + 5, y + h // 2) != self.monitor:
set_strut = False
elif self.globals.settings["dock/position"] == "top":
strut = [0, 0, y + h, 0, 0, 0, 0, 0, x, x + w - 1, 0, 0]
if s.get_monitor_at_point(x + w // 2, my - 5) != self.monitor:
set_strut = False
else:
strut = [0, 0, 0, sh - y, 0, 0, 0, 0, 0, 0, x, x + w - 1]
if s.get_monitor_at_point(x + w // 2, my + mh + 5) != self.monitor:
set_strut = False
if not set_strut:
d = display.Display()
topw = d.create_resource_object('window',
self.get_toplevel().get_window().get_xid())
topw.delete_property(d.intern_atom("_NET_WM_STRUT"))
topw.delete_property(d.intern_atom("_NET_WM_STRUT_PARTIAL"))
return
d = display.Display()
topw = d.create_resource_object('window',
self.get_toplevel().get_window().get_xid())
Expand Down

0 comments on commit e7b8fb9

Please sign in to comment.