Move Cosmic Applets into new Dir & remove old applets

This commit is contained in:
13r0ck 2022-12-22 19:56:42 -07:00 • committed by Ashley Wulber
parent 813e6c0aff
commit a682b8deb0
134 changed files with 0 additions and 1354 deletions

3414
cosmic-applet-time/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,12 @@
[package]
name = "cosmic-applet-time"
version = "0.1.0"
edition = "2021"
license = "GPL-3.0-or-later"
[dependencies]
icon-loader = { version = "0.3.6", features = ["gtk"] }
tokio = { version = "1.20.1", features=["full"] }
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
nix = "0.24.1"
chrono = { version = "0.4.23", features = ["clock"] }

View file

@ -0,0 +1,10 @@
[Desktop Entry]
Name=Cosmic Applet Time
Type=Application
Exec=cosmic-applet-time
Terminal=false
Categories=GNOME;GTK;
Keywords=Gnome;GTK;
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
Icon=com.system76.CosmicAppletTime
NoDisplay=true

View file

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="128px" height="128px" viewBox="0 0 128 128" version="1.1">
<defs>
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
</filter>
<mask id="mask0">
<g filter="url(#alpha)">
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
</g>
</mask>
<clipPath id="clip1">
<rect x="0" y="0" width="192" height="152"/>
</clipPath>
<g id="surface10632" clip-path="url(#clip1)">
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 123.503906 236 C 123.503906 268.863281 96.863281 295.503906 64 295.503906 C 31.136719 295.503906 4.496094 268.863281 4.496094 236 C 4.496094 203.136719 31.136719 176.496094 64 176.496094 C 96.863281 176.496094 123.503906 203.136719 123.503906 236 Z M 123.503906 236 " transform="matrix(1,0,0,1,8,-156)"/>
</g>
<mask id="mask1">
<g filter="url(#alpha)">
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
</g>
</mask>
<clipPath id="clip2">
<rect x="0" y="0" width="192" height="152"/>
</clipPath>
<g id="surface10635" clip-path="url(#clip2)">
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 29.195312 180.496094 L 98.804688 180.496094 C 103.609375 180.496094 107.503906 184.046875 107.503906 188.425781 L 107.503906 283.574219 C 107.503906 287.953125 103.609375 291.503906 98.804688 291.503906 L 29.195312 291.503906 C 24.390625 291.503906 20.496094 287.953125 20.496094 283.574219 L 20.496094 188.425781 C 20.496094 184.046875 24.390625 180.496094 29.195312 180.496094 Z M 29.195312 180.496094 " transform="matrix(1,0,0,1,8,-156)"/>
</g>
<mask id="mask2">
<g filter="url(#alpha)">
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
</g>
</mask>
<clipPath id="clip3">
<rect x="0" y="0" width="192" height="152"/>
</clipPath>
<g id="surface10638" clip-path="url(#clip3)">
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 20.417969 184.496094 L 107.582031 184.496094 C 111.957031 184.496094 115.503906 188.042969 115.503906 192.417969 L 115.503906 279.582031 C 115.503906 283.957031 111.957031 287.503906 107.582031 287.503906 L 20.417969 287.503906 C 16.042969 287.503906 12.496094 283.957031 12.496094 279.582031 L 12.496094 192.417969 C 12.496094 188.042969 16.042969 184.496094 20.417969 184.496094 Z M 20.417969 184.496094 " transform="matrix(1,0,0,1,8,-156)"/>
</g>
<mask id="mask3">
<g filter="url(#alpha)">
<rect x="0" y="0" width="128" height="128" style="fill:rgb(0%,0%,0%);fill-opacity:0.1;stroke:none;"/>
</g>
</mask>
<clipPath id="clip4">
<rect x="0" y="0" width="192" height="152"/>
</clipPath>
<g id="surface10641" clip-path="url(#clip4)">
<path style="fill:none;stroke-width:0.99;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:0.99,0.99;stroke-miterlimit:4;" d="M 16.425781 200.496094 L 111.574219 200.496094 C 115.953125 200.496094 119.503906 204.390625 119.503906 209.195312 L 119.503906 278.804688 C 119.503906 283.609375 115.953125 287.503906 111.574219 287.503906 L 16.425781 287.503906 C 12.046875 287.503906 8.496094 283.609375 8.496094 278.804688 L 8.496094 209.195312 C 8.496094 204.390625 12.046875 200.496094 16.425781 200.496094 Z M 16.425781 200.496094 " transform="matrix(1,0,0,1,8,-156)"/>
</g>
</defs>
<g id="surface10578">
<rect x="0" y="0" width="128" height="128" style="fill:rgb(94.117647%,94.117647%,94.117647%);fill-opacity:1;stroke:none;"/>
<use xlink:href="#surface10632" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask0)"/>
<use xlink:href="#surface10635" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask1)"/>
<use xlink:href="#surface10638" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask2)"/>
<use xlink:href="#surface10641" transform="matrix(1,0,0,1,-8,-16)" mask="url(#mask3)"/>
<path style="fill:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.431373%,62.7451%,91.764706%);stroke-opacity:1;stroke-miterlimit:4;" d="M 0 289 L 128 289 " transform="matrix(1,0,0,1,0,-172)"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

View file

@ -0,0 +1,175 @@
use cosmic::applet::CosmicAppletHelper;
use cosmic::iced::wayland::{
popup::{destroy_popup, get_popup},
SurfaceIdWrapper,
};
use cosmic::iced::{
executor, time,
widget::{button, column, text},
window, Alignment, Application, Color, Command, Length, Subscription,
};
use cosmic::iced_style::application::{self, Appearance};
use cosmic::theme;
use cosmic::{Element, Theme};
use chrono::{DateTime, Local, Timelike};
use std::time::Duration;
pub fn main() -> cosmic::iced::Result {
let mut helper = CosmicAppletHelper::default();
helper.window_size(120, 16);
Time::run(helper.window_settings())
}
struct Time {
applet_helper: CosmicAppletHelper,
theme: Theme,
popup: Option<window::Id>,
id_ctr: u32,
update_at: Every,
now: DateTime<Local>,
}
impl Default for Time {
fn default() -> Self {
Time {
applet_helper: CosmicAppletHelper::default(),
theme: Theme::default(),
popup: None,
id_ctr: 0,
update_at: Every::Minute,
now: Local::now(),
}
}
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
enum Every {
Minute,
Second,
}
#[derive(Debug, Clone)]
enum Message {
TogglePopup,
Tick,
Ignore,
}
impl Application for Time {
type Message = Message;
type Theme = Theme;
type Executor = executor::Default;
type Flags = ();
fn new(_flags: ()) -> (Time, Command<Message>) {
(Time::default(), Command::none())
}
fn title(&self) -> String {
String::from("Time")
}
fn theme(&self) -> Theme {
self.theme
}
fn close_requested(&self, _id: SurfaceIdWrapper) -> Self::Message {
Message::Ignore
}
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
text_color: theme.cosmic().on_bg_color().into(),
})
}
fn subscription(&self) -> Subscription<Message> {
const FALLBACK_DELAY: u64 = 500;
let update_delay = match self.update_at {
Every::Minute => chrono::Duration::minutes(1),
Every::Second => chrono::Duration::seconds(1),
};
// Calculate the time until next second/minute so we can sleep the thread until then.
let now = Local::now().time();
let next = (now + update_delay)
.with_second(0)
.expect("Setting seconds to 0 should always be possible")
.with_nanosecond(0)
.expect("Setting nanoseconds to 0 should always be possible.");
let wait = (next - now).num_milliseconds();
time::every(Duration::from_millis(
wait.try_into().unwrap_or(FALLBACK_DELAY),
))
.map(|_| Message::Tick)
}
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::TogglePopup => {
if let Some(p) = self.popup.take() {
destroy_popup(p)
} else {
self.id_ctr += 1;
let new_id = window::Id::new(self.id_ctr);
self.popup.replace(new_id);
let popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
new_id,
(400, 300),
Some(60),
None,
);
get_popup(popup_settings)
}
}
Message::Tick => {
self.now = Local::now();
Command::none()
}
Message::Ignore => Command::none(),
}
}
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
match id {
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
SurfaceIdWrapper::Window(_) => button(
column![text(self.now.format("%b %-d %-I:%M %p").to_string())]
.width(Length::Fill)
.align_items(Alignment::Center),
)
.on_press(Message::TogglePopup)
.style(theme::Button::Text)
.width(Length::Units(120))
.into(),
SurfaceIdWrapper::Popup(_) => {
use std::os::unix::process::ExitStatusExt;
let calendar = std::str::from_utf8(
&std::process::Command::new("happiness")
.output()
.unwrap_or(std::process::Output {
stdout: "`sudo apt install happiness`".as_bytes().to_vec(),
stderr: Vec::new(),
status: std::process::ExitStatus::from_raw(0),
})
.stdout,
)
.unwrap()
.to_string();
let content = column![]
.align_items(Alignment::Start)
.spacing(12)
.padding([24, 0])
.push(text(calendar));
self.applet_helper.popup_container(content).into()
}
}
}
}