Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
World
Design Tooling
Contrast
Commits
4b5ea8f9
Commit
4b5ea8f9
authored
Feb 21, 2020
by
Bilal Elmoussaoui
Browse files
clean my silly mistakes
not all of them
parent
de2a469d
Changes
15
Hide whitespace changes
Inline
Side-by-side
Cargo.lock
View file @
4b5ea8f9
...
...
@@ -41,26 +41,6 @@ dependencies = [
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace"
version = "0.3.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace-sys"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.1.0"
...
...
@@ -113,7 +93,6 @@ name = "contrast"
version = "0.0.2"
dependencies = [
"dbus 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gettext-rs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
...
...
@@ -149,26 +128,6 @@ dependencies = [
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "failure"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "failure_derive"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "futures-channel"
version = "0.3.4"
...
...
@@ -687,11 +646,6 @@ dependencies = [
"ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-demangle"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "sass-rs"
version = "0.2.2"
...
...
@@ -727,17 +681,6 @@ dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synstructure"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termcolor"
version = "1.0.5"
...
...
@@ -810,8 +753,6 @@ dependencies = [
"checksum atk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "444daefa55f229af145ea58d77efd23725024ee1f6f3102743709aa6b18c663e"
"checksum atk-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e552c1776737a4c80110d06b36d099f47c727335f9aaa5d942a72b6863a8ec6f"
"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
"checksum backtrace 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)" = "a4ed64ae6d9ebfd9893193c4b2532b1292ec97bd8271c9d7d0fa90cd78a34cba"
"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491"
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
"checksum cairo-rs 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "157049ba9618aa3a61c39d5d785102c04d3b1f40632a706c621a9aedc21e6084"
...
...
@@ -820,8 +761,6 @@ dependencies = [
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum dbus 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "48b5f0f36f1eebe901b0e6bee369a77ed3396334bf3f09abd46454a576f71819"
"checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9"
"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"
"checksum futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8"
"checksum futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a"
"checksum futures-executor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba"
...
...
@@ -872,12 +811,10 @@ dependencies = [
"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
"checksum regex 1.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d9d8297cc20bbb6184f8b45ff61c8ee6a9ac56c156cec8e38c3e5084773c44ad"
"checksum regex-syntax 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "9b01330cce219c1c6b2e209e5ed64ccd587ae5c67bed91c0b49eecf02ae40e21"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum sass-rs 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cabcf7c6e55053f359911187ac401409aad2dc14338cae972dec266fee486abd"
"checksum sass-sys 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6e16ac97c2335bc367e2d675f54c1823558f1b19a6c67671d48b70e30ae22972"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5"
"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
"checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
...
...
data/resources.gresource.xml
View file @
4b5ea8f9
...
...
@@ -3,7 +3,6 @@
<gresource
prefix=
"/org/gnome/design/Contrast/"
>
<file
compressed=
"true"
preprocess=
"xml-stripblanks"
>
about_dialog.ui
</file>
<file
compressed=
"true"
preprocess=
"xml-stripblanks"
alias=
"shortcuts.ui"
>
resources/ui/shortcuts.ui
</file>
<file
compressed=
"true"
preprocess=
"xml-stripblanks"
alias=
"menu.ui"
>
resources/ui/menu.ui
</file>
<file
compressed=
"true"
preprocess=
"xml-stripblanks"
>
window.ui
</file>
<file
compressed=
"true"
alias=
"style.css"
>
resources/style.css
</file>
</gresource>
...
...
data/resources/ui/menu.ui
deleted
100644 → 0
View file @
de2a469d
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<menu
id=
"popover_menu"
>
<item>
<attribute
name=
"label"
translatable=
"yes"
>
_Keyboard Shortcuts
</attribute>
<attribute
name=
"action"
>
win.show-help-overlay
</attribute>
</item>
<item>
<attribute
name=
"label"
translatable=
"yes"
>
_About Contrast
</attribute>
<attribute
name=
"action"
>
app.about
</attribute>
</item>
</menu>
</interface>
data/resources/ui/shortcuts.ui
View file @
4b5ea8f9
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object
class=
"GtkShortcutsWindow"
id=
"shortcuts"
>
<object
class=
"GtkShortcutsWindow"
id=
"shortcuts
_dialog
"
>
<property
name=
"modal"
>
True
</property>
<child>
<object
class=
"GtkShortcutsSection"
>
...
...
data/resources/ui/window.ui.in
View file @
4b5ea8f9
...
...
@@ -2,7 +2,51 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires
lib=
"gtk+"
version=
"3.20"
/>
<object
class=
"GtkApplicationWindow"
id=
"window"
>
<object
class=
"GtkPopoverMenu"
id=
"popover"
>
<property
name=
"can_focus"
>
False
</property>
<child>
<object
class=
"GtkBox"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
False
</property>
<property
name=
"border_width"
>
10
</property>
<property
name=
"orientation"
>
vertical
</property>
<child>
<object
class=
"GtkModelButton"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
False
</property>
<property
name=
"receives_default"
>
False
</property>
<property
name=
"action_name"
>
win.show-help-overlay
</property>
<property
name=
"text"
translatable=
"yes"
>
_Keyboard Shortcuts
</property>
</object>
<packing>
<property
name=
"expand"
>
False
</property>
<property
name=
"fill"
>
True
</property>
<property
name=
"position"
>
4
</property>
</packing>
</child>
<child>
<object
class=
"GtkModelButton"
>
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
False
</property>
<property
name=
"receives_default"
>
False
</property>
<property
name=
"action_name"
>
app.about
</property>
<property
name=
"text"
translatable=
"yes"
>
_About Contrast
</property>
</object>
<packing>
<property
name=
"expand"
>
False
</property>
<property
name=
"fill"
>
True
</property>
<property
name=
"position"
>
7
</property>
</packing>
</child>
</object>
<packing>
<property
name=
"submenu"
>
main
</property>
<property
name=
"position"
>
1
</property>
</packing>
</child>
</object>
<object
class=
"GtkApplicationWindow"
id=
"window_widget"
>
<property
name=
"can_focus"
>
False
</property>
<property
name=
"title"
translatable=
"yes"
>
@name-prefix@Contrast
</property>
<property
name=
"default_width"
>
650
</property>
...
...
@@ -20,6 +64,7 @@
<property
name=
"visible"
>
True
</property>
<property
name=
"can_focus"
>
True
</property>
<property
name=
"receives_default"
>
True
</property>
<property
name=
"popover"
>
popover
</property>
<child>
<object
class=
"GtkImage"
>
<property
name=
"visible"
>
True
</property>
...
...
po/POTFILES.in
View file @
4b5ea8f9
...
...
@@ -2,7 +2,6 @@ data/org.gnome.design.Contrast.appdata.xml.in.in
data/org.gnome.design.Contrast.desktop.in.in
data/org.gnome.design.Contrast.gschema.xml.in
data/resources/ui/about_dialog.ui.in
data/resources/ui/menu.ui
data/resources/ui/shortcuts.ui
data/resources/ui/window.ui.in
src/contrast_level.rs
...
...
src/application.rs
View file @
4b5ea8f9
use
super
::
colour
;
use
super
::
config
;
use
super
::
styles
::
update_style
s
;
use
super
::
util
s
;
use
super
::
window
::
Window
;
use
gio
::
prelude
::
*
;
use
glib
::
{
Receiver
,
Sender
}
;
use
glib
::
Receiver
;
use
gtk
::
prelude
::
*
;
use
gtk
::
SettingsExt
;
use
std
::
env
;
...
...
@@ -11,38 +11,24 @@ use std::{cell::RefCell, rc::Rc};
pub
enum
Action
{
ApplyStylesheet
(
String
),
ColorChanged
,
}
pub
struct
Application
{
app
:
gtk
::
Application
,
window
:
Window
,
window
:
Rc
<
Window
>
,
provider
:
gtk
::
CssProvider
,
sender
:
Sender
<
Action
>
,
receiver
:
RefCell
<
Option
<
Receiver
<
Action
>>>
,
}
impl
Application
{
pub
fn
new
()
->
Rc
<
Self
>
{
let
app
=
gtk
::
Application
::
new
(
Some
(
config
::
APP_ID
),
gio
::
ApplicationFlags
::
FLAGS_NONE
)
.unwrap
();
let
(
sender
,
r
)
=
glib
::
MainContext
::
channel
(
glib
::
PRIORITY_DEFAULT
);
let
receiver
=
RefCell
::
new
(
Some
(
r
));
let
window
=
Window
::
new
(
sender
.clone
());
let
builder
=
gtk
::
Builder
::
new_from_resource
(
"/org/gnome/design/Contrast/shortcuts.ui"
);
let
dialog
:
gtk
::
ShortcutsWindow
=
builder
.get_object
(
"shortcuts"
)
.unwrap
();
window
.widget
.set_help_overlay
(
Some
(
&
dialog
));
let
window
=
Window
::
new
(
sender
);
let
provider
=
gtk
::
CssProvider
::
new
();
let
application
=
Rc
::
new
(
Self
{
app
,
window
,
provider
,
sender
,
receiver
,
});
let
application
=
Rc
::
new
(
Self
{
app
,
window
,
provider
,
receiver
});
application
.setup_gactions
();
application
.setup_signals
();
application
.setup_css
();
...
...
@@ -51,35 +37,42 @@ impl Application {
fn
setup_gactions
(
&
self
)
{
// Quit
let
app
=
self
.app
.clone
();
let
simple_action
=
gio
::
SimpleAction
::
new
(
"quit"
,
None
);
simple_action
.connect_activate
(
move
|
_
,
_
|
app
.quit
());
self
.app
.add_action
(
&
simple_action
);
utils
::
action
(
&
self
.app
,
"quit"
,
None
,
clone!
(
@
strong
self
.app
as
app
=>
move
|
_
,
_
|
{
app
.quit
();
}),
);
// About
utils
::
action
(
&
self
.app
,
"about"
,
None
,
clone!
(
@
weak
self
.window.widget
as
window
=>
move
|
_
,
_
|
{
let
builder
=
gtk
::
Builder
::
new_from_resource
(
"/org/gnome/design/Contrast/about_dialog.ui"
);
get_widget!
(
builder
,
gtk
::
AboutDialog
,
about_dialog
);
about_dialog
.set_transient_for
(
Some
(
&
window
));
about_dialog
.connect_response
(|
dialog
,
_
|
dialog
.destroy
());
about_dialog
.show
();
}),
);
// Accels
self
.app
.set_accels_for_action
(
"app.quit"
,
&
[
"<primary>q"
]);
self
.app
.set_accels_for_action
(
"win.show-help-overlay"
,
&
[
"<primary>question"
]);
self
.app
.set_accels_for_action
(
"window.reverse-colors"
,
&
[
"<primary>r"
]);
// About
let
window
=
self
.window.widget
.clone
();
let
simple_action
=
gio
::
SimpleAction
::
new
(
"about"
,
None
);
simple_action
.connect_activate
(
move
|
_
,
_
|
{
let
builder
=
gtk
::
Builder
::
new_from_resource
(
"/org/gnome/design/Contrast/about_dialog.ui"
);
let
about_dialog
:
gtk
::
AboutDialog
=
builder
.get_object
(
"about_dialog"
)
.unwrap
();
about_dialog
.set_transient_for
(
Some
(
&
window
));
about_dialog
.connect_response
(|
dialog
,
_
|
dialog
.destroy
());
about_dialog
.show
();
});
self
.app
.add_action
(
&
simple_action
);
}
fn
setup_signals
(
&
self
)
{
let
window
=
self
.window.widget
.clone
();
self
.app
.connect_activate
(
move
|
app
|
{
self
.app
.connect_activate
(
clone!
(
@
weak
self
.window.widget
as
window
=>
move
|
app
|
{
window
.set_application
(
Some
(
app
));
app
.add_window
(
&
window
);
window
.present
();
});
})
)
;
}
fn
setup_css
(
&
self
)
{
...
...
@@ -87,35 +80,25 @@ impl Application {
gtk_settings
.set_property_gtk_theme_name
(
Some
(
"Adwaita"
));
}
let
theme
=
gtk
::
IconTheme
::
get_default
()
.unwrap
();
theme
.add_resource_path
(
"/org/gnome/design/Contrast/icons"
);
gtk
::
StyleContext
::
add_provider_for_screen
(
&
gdk
::
Screen
::
get_default
()
.unwrap
(),
&
self
.provider
,
400
);
if
let
Some
(
theme
)
=
gtk
::
IconTheme
::
get_default
()
{
theme
.add_resource_path
(
"/org/gnome/design/Contrast/icons"
);
}
let
p
=
gtk
::
CssProvider
::
new
();
gtk
::
CssProvider
::
load_from_resource
(
&
p
,
"/org/gnome/design/Contrast/style.css"
);
gtk
::
StyleContext
::
add_provider_for_screen
(
&
gdk
::
Screen
::
get_default
()
.unwrap
(),
&
p
,
500
);
if
let
Some
(
screen
)
=
gdk
::
Screen
::
get_default
()
{
gtk
::
StyleContext
::
add_provider_for_screen
(
&
screen
,
&
self
.provider
,
400
);
self
.sender
.send
(
Action
::
ColorChanged
)
.ok
();
// never fails
let
p
=
gtk
::
CssProvider
::
new
();
gtk
::
CssProvider
::
load_from_resource
(
&
p
,
"/org/gnome/design/Contrast/style.css"
);
gtk
::
StyleContext
::
add_provider_for_screen
(
&
screen
,
&
p
,
500
);
}
}
fn
do_action
(
&
self
,
action
:
Action
)
->
glib
::
Continue
{
match
action
{
Action
::
ApplyStylesheet
(
text
)
=>
{
match
self
.provider
.load_from_data
(
text
.as_bytes
())
{
Ok
(
_
)
=>
(),
Err
(
err
)
=>
error!
(
"Stylesheet couldn't be updated {}"
,
err
),
};
}
Action
::
ColorChanged
=>
{
let
fg_colour
=
self
.window.state
.borrow
()
.fg_colour
;
let
bg_colour
=
self
.window.state
.borrow
()
.bg_colour
;
let
contrast_level
=
colour
::
calc_contrast_level
(
&
bg_colour
,
&
fg_colour
);
self
.window.levelbar
.borrow_mut
()
.set_contrast_level
(
contrast_level
);
self
.window.preview
.borrow_mut
()
.set_contrast_level
(
contrast_level
);
update_styles
(
&
self
.sender
,
fg_colour
,
bg_colour
);
if
let
Err
(
err
)
=
self
.provider
.load_from_data
(
text
.as_bytes
())
{
error!
(
"Stylesheet couldn't be updated {}"
,
err
);
}
}
};
glib
::
Continue
(
true
)
...
...
src/colour_entry.rs
View file @
4b5ea8f9
use
super
::
colour
;
use
super
::
colour_popover
::
ColourPopover
;
use
dbus
::{
BusType
,
Connection
,
Message
}
;
use
super
::
utils
;
use
gtk
::
prelude
::
*
;
use
std
::
collections
::
HashMap
;
use
std
::
str
::
FromStr
;
#[derive(Clone)]
...
...
@@ -39,30 +38,29 @@ impl ColourEntry {
self
.entry
.set_width_chars
(
10
);
self
.entry
.show
();
let
colour_
selector_
popover
=
ColourPopover
::
new
(
self
.entry
.clone
());
let
colour_popover
=
ColourPopover
::
new
(
self
.entry
.clone
());
let
colour_selector_pop
=
colour_selector_popover
.clone
();
self
.entry
.connect_icon_press
(
move
|
entry
,
_
,
_
|
{
self
.entry
.connect_icon_press
(
clone!
(
@
strong
colour_popover
=>
move
|
entry
,
_
,
_
|
{
let
icon_rectangle
=
entry
.get_icon_area
(
gtk
::
EntryIconPosition
::
Primary
);
colour_
selector_pop
.widget
.set_pointing_to
(
&
icon_rectangle
);
colour_
popover
.widget
.set_pointing_to
(
&
icon_rectangle
);
let
colour
=
entry
.get_text
()
.unwrap
();
if
let
Ok
(
rgba
)
=
gdk
::
RGBA
::
from_str
(
&
colour
)
{
colour_
selector_pop
.color_chooser
.set_rgba
(
&
rgba
);
colour_
popover
.color_chooser
.set_rgba
(
&
rgba
);
}
colour_
selector_pop
.color_chooser
.set_property_show_editor
(
false
);
colour_
selector_pop
.widget
.popup
();
});
let
colo
u
r_
selector_pop
=
colour_selector_popover
.clone
();
let
entry
=
self
.entry
.clone
();
colour_selector_popover
.color_chooser
.connect_button_press_event
(
move
|
_
,
_
|
{
let
colour
=
colour_
selector_pop
.color_chooser
.get_rgba
();
colour_
popover
.color_chooser
.set_property_show_editor
(
false
);
colour_
popover
.widget
.popup
();
})
)
;
colour_popover
.
color_
chooser
.connect_button_press_event
(
clone!
(
@
strong
colour_popover
,
@
weak
self
.entry
as
entry
=>
@
default
-
return
gtk
::
Inhibit
(
false
),
move
|
_
,
_
|
{
let
colour
=
colour_
popover
.color_chooser
.get_rgba
();
let
hex_colour
=
colour
::
rgba_to_hex
(
&
colour
);
entry
.set_text
(
&
hex_colour
);
colour_
selector_pop
.widget
.popdown
();
colour_
popover
.widget
.popdown
();
gtk
::
Inhibit
(
false
)
});
})
)
;
self
.widget
.pack_start
(
&
self
.entry
,
false
,
false
,
0
);
...
...
@@ -73,26 +71,12 @@ impl ColourEntry {
colour_selector
.show
();
self
.widget
.pack_start
(
&
colour_selector
,
false
,
false
,
0
);
let
entry
=
self
.entry
.clone
();
colour_selector
.connect_clicked
(
move
|
_
|
match
Connection
::
get_private
(
BusType
::
Session
)
{
Ok
(
conn
)
=>
{
let
msg
=
Message
::
new_method_call
(
"org.gnome.Shell.Screenshot"
,
"/org/gnome/Shell/Screenshot"
,
"org.gnome.Shell.Screenshot"
,
"PickColor"
)
.unwrap
();
match
conn
.send_with_reply_and_block
(
msg
,
60000
)
{
Ok
(
response
)
=>
{
let
result
:
HashMap
<
String
,
dbus
::
arg
::
Variant
<
Box
<
dyn
dbus
::
arg
::
RefArg
>>
,
_
>
=
response
.get1
()
.unwrap
();
let
mut
color
=
result
.get
(
"color"
)
.unwrap
()
.0
.as_iter
()
.unwrap
();
let
red
=
color
.next
()
.unwrap
()
.as_f64
()
.unwrap
();
let
green
=
color
.next
()
.unwrap
()
.as_f64
()
.unwrap
();
let
blue
=
color
.next
()
.unwrap
()
.as_f64
()
.unwrap
();
let
rgb
=
gdk
::
RGBA
{
red
,
green
,
blue
,
alpha
:
1.0
};
entry
.set_text
(
&
colour
::
rgba_to_hex
(
&
rgb
));
}
Err
(
err
)
=>
error!
(
"Failed to call PickColor {}"
,
err
),
}
colour_selector
.connect_clicked
(
clone!
(
@
weak
self
.entry
as
entry
=>
move
|
_
|
{
match
utils
::
pick_color
()
{
Ok
(
rgba
)
=>
entry
.set_text
(
&
colour
::
rgba_to_hex
(
&
rgba
)),
Err
(
_
)
=>
warn!
(
"Failed to pick a color"
),
}
Err
(
err
)
=>
error!
(
"Failed to create a session Bus {}"
,
err
),
});
}));
self
.widget
.show
();
}
...
...
src/colour_popover.rs
View file @
4b5ea8f9
...
...
@@ -80,10 +80,9 @@ impl ColourPopover {
container
.pack_start
(
&
back_btn
,
false
,
false
,
6
);
container
.pack_start
(
&
self
.color_chooser
,
false
,
false
,
0
);
let
color_chooser
=
self
.color_chooser
.clone
();
back_btn
.connect_clicked
(
move
|
_
|
{
back_btn
.connect_clicked
(
clone!
(
@
weak
self
.color_chooser
as
color_chooser
=>
move
|
_
|
{
color_chooser
.set_property_show_editor
(
false
);
});
})
)
;
self
.color_chooser
.set_halign
(
gtk
::
Align
::
Start
);
self
.color_chooser
.set_valign
(
gtk
::
Align
::
Center
);
...
...
src/contrast_level.rs
View file @
4b5ea8f9
...
...
@@ -30,35 +30,29 @@ impl ChartBarWidget {
filled_container
:
gtk
::
Box
::
new
(
gtk
::
Orientation
::
Horizontal
,
0
),
markers
:
Rc
::
new
(
RefCell
::
new
(
Vec
::
new
())),
}));
Self
::
init
(
&
chart_bar
);
chart_bar
.borrow
()
.init
(
chart_bar
.clone
());
chart_bar
}
pub
fn
init
(
s
:
&
Rc
<
RefCell
<
Self
>>
)
{
let
container
=
&
s
.borrow
()
.container
;
let
filled_container
=
&
s
.borrow
()
.filled_container
;
let
widget
=
&
s
.borrow
()
.widget
;
container
.set_valign
(
gtk
::
Align
::
Center
);
container
.set_halign
(
gtk
::
Align
::
Fill
);
container
.set_hexpand
(
true
);
container
.get_style_context
()
.add_class
(
"chart-bar"
);
fn
init
(
&
self
,
chart_bar
:
Rc
<
RefCell
<
Self
>>
)
{
self
.container
.set_valign
(
gtk
::
Align
::
Center
);
self
.container
.set_halign
(
gtk
::
Align
::
Fill
);
self
.container
.set_hexpand
(
true
);
self
.container
.get_style_context
()
.add_class
(
"chart-bar"
);
let
drawing_area
=
gtk
::
DrawingArea
::
new
();
drawing_area
.show
();
let
overlay
=
gtk
::
Overlay
::
new
();
overlay
.set_property_height_request
(
60
);
overlay
.add
(
container
);
overlay
.add
(
&
self
.
container
);
overlay
.add_overlay
(
&
drawing_area
);
overlay
.set_overlay_pass_through
(
&
drawing_area
,
true
);
overlay
.show
();
let
markers
=
&
s
.borrow
()
.markers
;
let
weak_markers
=
Rc
::
downgrade
(
markers
);
let
n_blocks
=
&
s
.borrow
()
.max_value
-
0.0
;
let
n_blocks
=
self
.max_value
-
0.0
;
drawing_area
.connect_draw
(
move
|
widget
,
context
|
{
drawing_area
.connect_draw
(
clone!
(
@
strong
self
.markers
as
markers
=>
move
|
widget
,
context
|
{
let
style_context
=
widget
.get_style_context
();
let
pango_context
=
widget
.get_pango_context
()
.unwrap
();
let
allocation
=
widget
.get_allocation
();
...
...
@@ -73,38 +67,37 @@ impl ChartBarWidget {
font_description
.set_absolute_size
((
12
*
pango
::
SCALE
)
.into
());
font_description
.set_weight
(
pango
::
Weight
::
Semibold
);
if
let
Some
(
markers
)
=
weak_markers
.upgrade
()
{
for
marker
in
markers
.borrow
()
.iter
()
{
let
marker_x
=
block_width
*
marker
.position
.log
(
10.0
);
// Draw the ticks
context
.move_to
(
marker_x
,
(
allocation
.y
+
15
)
.into
());
context
.line_to
(
marker_x
,
(
allocation
.y
+
allocation
.height
-
24
)
as
f64
);
context
.stroke
();
// draw the tick's label
let
label_length
=
marker
.name
.chars
()
.count
()
as
f64
;
context
.move_to
(
marker_x
-
label_length
*
3.5
,
(
allocation
.y
)
as
f64
);
let
layout
=
pango
::
Layout
::
new
(
&
pango_context
);
layout
.set_font_description
(
Some
(
&
font_description
));
layout
.set_text
(
&
marker
.name
);
pangocairo
::
functions
::
show_layout
(
&
context
,
&
layout
);
}
for
marker
in
markers
.borrow
()
.iter
()
{
let
marker_x
=
block_width
*
marker
.position
.log
(
10.0
);
// Draw the ticks
context
.move_to
(
marker_x
,
(
allocation
.y
+
15
)
.into
());
context
.line_to
(
marker_x
,
(
allocation
.y
+
allocation
.height
-
24
)
as
f64
);
context
.stroke
();
// draw the tick's label
let
label_length
=
marker
.name
.chars
()
.count
()
as
f64
;
context
.move_to
(
marker_x
-
label_length
*
3.5
,
(
allocation
.y
)
as
f64
);
let
layout
=
pango
::
Layout
::
new
(
&
pango_context
);
layout
.set_font_description
(
Some
(
&
font_description
));
layout
.set_text
(
&
marker
.name
);
pangocairo
::
functions
::
show_layout
(
&
context
,
&
layout
);
}
gtk
::
Inhibit
(
false
)
});
container
.show
();
})
)
;
self
.
container
.show
();
filled_container
.get_style_context
()
.add_class
(
"filled"
);
filled_container
.set_property_height_request
(
10
);
filled_container
.show
();
self
.
filled_container
.get_style_context
()
.add_class
(
"filled"
);
self
.
filled_container
.set_property_height_request
(
10
);
self
.
filled_container
.show
();
container
.pack_start
(
filled_container
,
false
,
false
,
0
);
self
.
container
.pack_start
(
&
self
.
filled_container
,
false
,
false
,
0
);
widget
.set_maximum_width
(
900
);
widget
.add
(
&
overlay
);
widget
.show
();
self
.
widget
.set_maximum_width
(
900
);
self
.
widget
.add
(
&
overlay
);
self
.
widget
.show
();
container
.connect_size_allocate
(
clone!
(
@
weak
s
as
chart_bar
=>
move
|
_
,
_
|
{
self
.
container
.connect_size_allocate
(
clone!
(
@
weak
chart_bar
=>
move
|
_
,
_
|
{
chart_bar
.borrow
()
.reallocate
();
}));
}
...
...
src/main.rs
View file @
4b5ea8f9
...
...
@@ -5,6 +5,8 @@ extern crate log;
extern
crate
glib
;
use
gettextrs
::
*
;
#[macro_use]
mod
utils
;
mod
application
;
mod
colour
;
...
...
@@ -14,7 +16,6 @@ mod config;
mod
contrast_level
;
mod
contrast_preview
;
mod
static_resources
;