Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dimmer_all_monitors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
46 changes: 46 additions & 0 deletions data/Application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
window {
background-image:linear-gradient(#eef0f2, #a7b3c1);
}
.flat {
background-color: #eef0f2;
}
.knob-socket-graphic {
background-image:linear-gradient(alpha(#56626f, 0.5), alpha(#aebac6, 0.5), alpha(#fff, 0.5));
border-radius: 50%;
margin-left: -2px;
margin-top: -2px;
margin-right: 2px;
margin-bottom: 2px
}
.knob-cover-graphic {
background-image:linear-gradient(#e6eaed, #abb8c4);
border: 1px solid #56626f;
box-shadow: inset 0 1px 0 alpha(#fff, 0.7), inset 0 -1px 0 alpha(#56626f, 0.9),
0 2px 4px alpha(#000, 0.5), 0 -3px 4px alpha(#fff, 1.0);
border-radius: 50%;
margin: 6px
}
.knob-meter-graphic {
background-image:url("resource://com/github/watsonprojects/sundown/images/knob_meter.svg");
background-size: 132px;
background-position: center center;
}
.knob-meter-label {
font-size: 0.8rem;
margin-bottom: 4px;
color: #677892;
font-weight: 700;
text-shadow: 0 1px alpha(#fff, 0.5);
}
.knob-rim {
border: 1px solid shade(@accent_color, 1.3);
box-shadow: 0 0 4px @accent_color, 0 0 0 1px alpha(@accent_color, 0.2), inset 0 0 1px 1px @accent_color;
border-radius: 50%;
margin: 6px;
opacity: 1;
transition: opacity 1s ease;
}

.knob-rim-hidden {
opacity: 0;
}
9 changes: 9 additions & 0 deletions data/com.github.watsonprojects.sundown.gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/github/watsonprojects/sundown">
<file alias="Application.css">Application.css</file>
</gresource>
<gresource prefix="/com/github/watsonprojects/sundown/images">
<file alias="knob_meter.svg" compressed="true" preprocess="xml-stripblanks">images/knob_meter.svg</file>
</gresource>
</gresources>
27 changes: 27 additions & 0 deletions data/com.github.watsonprojects.sundown.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema path="/com/github/watsonprojects/sundown/" id="com.github.watsonprojects.sundown"
gettext-domain="com.github.watsonprojects.sundown">
<key name="all-monitors-brightness" type="d">
<default>0.54666666666666686</default>
<summary>Brightness settings of all monitors</summary>
</key>
<key name="monitors-1-brightness" type="d">
<default>0.54666666666666686</default>
<summary>Brightness settings for specific monitor</summary>
</key>
<key name="monitors-2-brightness" type="d">
<default>0.54666666666666686</default>
<summary>Brightness settings for specific monitor</summary>
</key>
<key name="monitors-3-brightness" type="d">
<default>0.54666666666666686</default>
<summary>Brightness settings for specific monitor</summary>
</key>
<key name="monitors-4-brightness" type="d">
<default>0.54666666666666686</default>
<summary>Brightness settings for specific monitor</summary>
</key>
</schema>
</schemalist>
26 changes: 26 additions & 0 deletions data/images/knob_meter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ i18n.merge_file (
install: true,
install_dir: join_paths (get_option ('datadir'), 'metainfo')
)

install_data(
'com.github.watsonprojects.sundown.gschema.xml',
rename: meson.project_name() + '.gschema.xml',
install_dir: get_option('datadir') / 'glib-2.0' / 'schemas'
)
18 changes: 16 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ project (
# Translation module
i18n = import ('i18n')

# GNOME module
gnome = import ('gnome')

# Project arguments
add_project_arguments (
'-DGETTEXT_PACKAGE="@0@"'.format (meson.project_name ()),
Expand All @@ -23,12 +26,23 @@ add_project_arguments(
# Listing dependencies
dependencies = [
dependency('gtk+-3.0'),
dependency('gee-0.8')
dependency('gee-0.8'),
meson.get_compiler ('c').find_library ('m', required : false)
]

# Compiling resources
asresources = gnome.compile_resources (
'as-resources',
'data/' + meson.project_name () + '.gresource.xml',
source_dir: 'data',
c_name: 'as'
)

# Executable
executable (
meson.project_name (),
asresources,
'src/Knob.vala',
'src/Sundown.vala',
dependencies: dependencies,
install: true
Expand All @@ -37,4 +51,4 @@ executable (
subdir ('data')
subdir ('po')

meson.add_install_script ('meson/post_install.py')
meson.add_install_script ('meson/post_install.py')
202 changes: 202 additions & 0 deletions src/Knob.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*-
* Copyright (c) 2021-2022 Subhadeep Jasu <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authored by: Subhadeep Jasu <[email protected]>
*/

public class Knob : Gtk.Overlay {
public string tooltip;
public bool dragging;
private double dragging_direction_x;
private double dragging_direction_y;
bool locked;

public double value = 27;
public int drag_force = 0;
protected Gtk.Box knob_socket_graphic;
protected Gtk.Box knob_cover;
protected Gtk.Box knob_background;
protected Gtk.Box knob_rim;
protected Gtk.Fixed fixed;
protected int center;

private Gtk.Label knob_label_dark;
private Gtk.Label knob_label_light;

protected const double RADIUS = 20;

public signal void change_value (double value);

public Knob () {
center = 42;
knob_socket_graphic = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
knob_socket_graphic.width_request = 20;
knob_socket_graphic.height_request = 20;
knob_socket_graphic.get_style_context ().add_class ("knob-socket-graphic");

knob_cover = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
knob_cover.get_style_context ().add_class ("knob-cover-graphic");
knob_cover.halign = Gtk.Align.START;
knob_cover.valign = Gtk.Align.START;
knob_cover.margin = 14;
knob_cover.width_request = 100;
knob_cover.height_request = 100;

fixed = new Gtk.Fixed ();
fixed.halign = Gtk.Align.START;
fixed.valign = Gtk.Align.START;
fixed.width_request = 100;
fixed.height_request = 100;
fixed.margin = 14;
double px = RADIUS * GLib.Math.cos (value / Math.PI);
double py = RADIUS * GLib.Math.sin (value / Math.PI);
fixed.put (knob_socket_graphic, (int)(px + center), (int)(py + center));

knob_background = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
knob_background.get_style_context ().add_class ("knob-meter-graphic");
knob_background.halign = Gtk.Align.START;
knob_background.valign = Gtk.Align.START;
knob_background.width_request = 128;
knob_background.height_request = 128;

knob_label_dark = new Gtk.Label (_("DARK"));
knob_label_dark.halign = Gtk.Align.START;
knob_label_dark.valign = Gtk.Align.END;
knob_label_dark.get_style_context ().add_class ("knob-meter-label");

knob_label_light = new Gtk.Label (_("LIGHT"));
knob_label_light.halign = Gtk.Align.END;
knob_label_light.valign = Gtk.Align.END;
knob_label_light.get_style_context ().add_class ("knob-meter-label");

knob_background.pack_start (knob_label_dark, true);
knob_background.pack_end (knob_label_light, true);

knob_rim = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
knob_rim.get_style_context ().add_class ("knob-rim");
knob_rim.halign = Gtk.Align.START;
knob_rim.valign = Gtk.Align.START;
knob_rim.margin = 14;
knob_rim.width_request = 100;
knob_rim.height_request = 100;

var event_box = new Gtk.EventBox ();
event_box.event.connect (handle_event);
event_box.hexpand = true;
event_box.vexpand = true;

add_overlay (knob_background);
add_overlay (knob_cover);
add_overlay (fixed);
add_overlay (knob_rim);
add_overlay (event_box);

this.hexpand = false;
this.vexpand = true;
this.width_request = 128;
this.height_request = 128;
}

public void rotate_dial (double value) {
double px = RADIUS * GLib.Math.cos (value / Math.PI);
double py = RADIUS * GLib.Math.sin (value / Math.PI);
fixed.move (knob_socket_graphic, (int)(px + center), (int)(py + center));
change_value ((value - 27.0) / 15.0);
}

public void set_value (double _value) {
value = 15 * _value + 27;
double px = RADIUS * GLib.Math.cos (value / Math.PI);
double py = RADIUS * GLib.Math.sin (value / Math.PI);
if (value == 35.2) {
knob_rim.get_style_context ().add_class ("knob-rim-hidden");
}
fixed.move (knob_socket_graphic, (int)(px + center), (int)(py + center));
}

public bool handle_event (Gdk.Event event) {
// if (event.type == Gdk.EventType.ENTER_NOTIFY) {
// this.get_toplevel.set_cursor (Gdk.CursorType.HAND1));
// }
// if (event.type == Gdk.EventType.LEAVE_NOTIFY) {
// fixed.set_cursor (Gdk.CursorType.ARROW);
// }
if (event.type == Gdk.EventType.BUTTON_PRESS) {
dragging = true;
drag_force = 0;
}
if (event.type == Gdk.EventType.BUTTON_RELEASE) {
dragging = false;
dragging_direction_x = 0;
dragging_direction_y = 0;
}

if (event.type == Gdk.EventType.MOTION_NOTIFY && dragging) {
if (dragging_direction_x == 0) {
dragging_direction_x = event.motion.x;
}
if (dragging_direction_y == 0) {
dragging_direction_y = event.motion.y;
}
double delta = 0.0;
if (dragging_direction_x > event.motion.x || event.motion.x_root == 0) {
delta -= 0.1 * (dragging_direction_x - event.motion.x);
if (locked) {
drag_force += 1;
}
dragging_direction_x = event.motion.x;
} else {
delta += 0.1 * (event.motion.x - dragging_direction_x);
if (locked) {
drag_force -= 1;
}
dragging_direction_x = event.motion.x;
}
if (dragging_direction_y > event.motion.y || event.motion.y_root == 0) {
delta += 0.1 * (dragging_direction_y - event.motion.y);
if (locked) {
drag_force += 1;
}
dragging_direction_y = event.motion.y;
} else {
delta -= 0.1 * (event.motion.y - dragging_direction_y);
if (locked) {
drag_force -= 1;
}
dragging_direction_y = event.motion.y;
}
value += delta;
if (value < 27) {
value = 27;
}
if (value > 42) {
value = 42;
}
if (value > 33.5 && value < 36.5 && !locked) {
value = 35.2;
locked = true;
knob_rim.get_style_context ().add_class ("knob-rim-hidden");
} else {
knob_rim.get_style_context ().remove_class ("knob-rim-hidden");
}
if (drag_force < -1 || drag_force > 1) {
locked = false;
}
rotate_dial (value);
}
return false;
}
}
Loading