Skip to content

Commit

Permalink
Scale the interface for HiDPI and do better with handling font DPI (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
twa022 authored Apr 12, 2022
1 parent 19e1413 commit 3dcebfe
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 20 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def datafilelist(installbase, sourcebase):
('{prefix}/share/mate/autostart/'.format(prefix=sys.prefix), ['usr/share/mate/autostart/mate-hud.desktop']),
('{prefix}/share/glib-2.0/schemas/'.format(prefix=sys.prefix), ['usr/share/glib-2.0/schemas/org.mate.hud.gschema.xml']),
('{prefix}/share/rofi/themes/'.format(prefix=sys.prefix), ['usr/share/rofi/themes/mate-hud.rasi']),
('{prefix}/share/rofi/themes/'.format(prefix=sys.prefix), ['usr/share/rofi/themes/mate-hud-hidpi.rasi']),
('{prefix}/share/rofi/themes/'.format(prefix=sys.prefix), ['usr/share/rofi/themes/mate-hud-rounded.rasi']),
('{prefix}/share/rofi/themes/'.format(prefix=sys.prefix), ['usr/share/rofi/themes/mate-hud-rounded-hidpi.rasi']),
]

cmdclass = {
Expand Down
28 changes: 8 additions & 20 deletions usr/lib/mate-hud/mate-hud
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,15 @@ def get_menu(menuKeys):
# Calculate display DPI value
screen = window.get_screen()
scale = window.get_scale_factor()

def get_dpi(pixels, mm):
if mm >= 1:
return scale * pixels / (mm / 25.4)
else:
return 0

width_dpi = get_dpi(screen.width(), screen.width_mm())
height_dpi = get_dpi(screen.height(), screen.height_mm())
dpi = scale * (width_dpi + height_dpi) / 2

if 'XFCE' in desktop_name:
xfce_custom_dpi = 0
try:
xfce_custom_dpi = Xfconf.Channel.new_with_property_base("xsettings", "/Xft").get_int("/DPI", 0)
except:
logging.debug('running XFCE, but xfconf gi repository not available')
if xfce_custom_dpi > 0:
dpi = xfce_custom_dpi
dpi = scale * screen.get_resolution()

rofi_theme = get_rofi_theme()
mate_hud_themes = [ 'mate-hud', 'mate-hud-hidpi', 'mate-hud-rounded', 'mate-hud-rounded-hidpi' ]
themes_hidpi_versions = { 'mate-hud': 'mate-hud-hidpi', 'mate-hud-rounded': 'mate-hud-rounded-hidpi' }
# switch to the hidpi version of the theme if needed.
if rofi_theme in mate_hud_themes:
if scale > 1 and rofi_theme in themes_hidpi_versions.keys():
rofi_theme = themes_hidpi_versions[rofi_theme]
cmd = ['rofi', '-dmenu', '-i',
'-p', 'HUD',
'-lines', '10',
Expand All @@ -250,7 +238,7 @@ def get_menu(menuKeys):

# If we use the default adaptive theme, we need to pull in some
# color information from the GTK theme
if rofi_theme == 'mate-hud' or rofi_theme == 'mate-hud-rounded' :
if rofi_theme in mate_hud_themes:
# Get the currently active font.
font_name = ''
if 'MATE' in desktop_name:
Expand Down
93 changes: 93 additions & 0 deletions usr/share/rofi/themes/mate-hud-hidpi.rasi
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* mate-hud rofi theme
* Incomplete theme designed to have certain properties applied at mate-hud runtime
* Don't use this for anything else than mate-hud
* Adapted by twa022 <twa022 at gmail dot com>
*/

configuration {

font: "Sans Regular 10";
line-margin: 10;
lines: 6;
columns: 2;

display-ssh: "";
display-run: "";
display-drun: "";
display-window: "";
display-combi: "";
show-icons: true;
}

* {
backlight: #ccffeedd;
background-color: transparent;
}

window {
location: north west;
anchor: north west;
width: 800px;
transparency: "screenshot";
border: 0px;

/* background-color: matched to GTK theme by mate-hud */
spacing: 0;
children: [mainbox];
orientation: horizontal;

margin: 24px 24px;

font: "Sans Regular 10";
}

mainbox {
spacing: 0;
children: [ inputbar, message, listview ];
}

inputbar {
/* text-color: matched to GTK theme by mate-hud */
padding: 22px;
/* background-color: matched to GTK theme by mate-hud */

border: 2px;
//border-radius: 6px 6px 0px 0px;
/* border-color: matched to GTK theme by mate-hud */
}

entry, prompt, case-indicator {
text-font: inherit;
text-color:inherit;
}

prompt {
margin: 0px 0.3em 0em 0em ;
}

listview {
padding: 16px;
/* border-color: matched to GTK theme by mate-hud */
border: 0px 2px 2px 2px;
/* background-color: matched to GTK theme by mate-hud */
dynamic: false;
font: "Sans Regular 10";
}

element {
padding: 6px 0px;
vertical-align: 0.5;
background-color: transparent;
/* text-color: matched to GTK theme by mate-hud */
}

element selected.normal {
/* background-color: matched to GTK theme by mate-hud */
/* text-color: matched to GTK theme by mate-hud */
}

element-text, element-icon {
background-color: inherit;
text-color: inherit;
}
96 changes: 96 additions & 0 deletions usr/share/rofi/themes/mate-hud-rounded-hidpi.rasi
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* mate-hud-rounded rofi theme (rounded corners)
* Incomplete theme designed to have certain properties applied at mate-hud runtime
* Don't use this for anything else than mate-hud
* Adapted by twa022 <twa022 at gmail dot com>
*/

configuration {

font: "Sans Regular 10";
line-margin: 10;
lines: 6;
columns: 2;

display-ssh: "";
display-run: "";
display-drun: "";
display-window: "";
display-combi: "";
show-icons: true;
}

* {
backlight: #ccffeedd;
background-color: transparent;
}

window {
location: north west;
anchor: north west;
width: 800px;
transparency: "screenshot";
border: 0px;
border-radius: 12px;

/* background-color: matched to GTK theme by mate-hud */
spacing: 0;
children: [mainbox];
orientation: horizontal;

margin: 24px 24px;

font: "Sans Regular 10";
}

mainbox {
spacing: 0;
children: [ inputbar, message, listview ];
}

inputbar {
/* text-color: matched to GTK theme by mate-hud */
padding: 22px;
/* background-color: matched to GTK theme by mate-hud */

border: 2px;
border-radius: 12px 12px 0px 0px;
/* border-color: matched to GTK theme by mate-hud */
}

entry, prompt, case-indicator {
text-font: inherit;
text-color:inherit;
}

prompt {
margin: 0px 0.3em 0em 0em ;
}

listview {
padding: 16px;
border-radius: 0px 0px 12px 12px;
/* border-color: matched to GTK theme by mate-hud */
border: 0px 2px 2px 2px;
/* background-color: matched to GTK theme by mate-hud */
dynamic: false;
font: "Sans Regular 10";
}

element {
padding: 6px;
vertical-align: 0.5;
border-radius: 8px;
background-color: transparent;
/* text-color: matched to GTK theme by mate-hud */
}

element selected.normal {
/* background-color: matched to GTK theme by mate-hud */
/* text-color: matched to GTK theme by mate-hud */
}

element-text, element-icon {
background-color: inherit;
text-color: inherit;
}

0 comments on commit 3dcebfe

Please sign in to comment.