From 0c6c3c6835f09f1e86d85a0abbaf15b51a89839a Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Fri, 28 Jun 2024 14:06:42 +0545 Subject: [PATCH] updates --- config/ags/.eslintrc.yml | 59 ++++++ config/ags/apps/settings/bluetooth.ts | 20 +- config/ags/apps/settings/main.ts | 10 +- config/ags/apps/settings/network.ts | 77 ++++---- config/ags/apps/settings/wallpapers.ts | 226 +++++++++++++++++++++++ config/ags/modules/notificationPopups.ts | 2 +- config/ags/style-apps.css | 108 ++++------- config/ags/style.css | 70 ++++++- config/ags/variables.ts | 20 ++ config/ags/wallpaper | 1 + 10 files changed, 474 insertions(+), 119 deletions(-) create mode 100644 config/ags/.eslintrc.yml create mode 100644 config/ags/apps/settings/wallpapers.ts create mode 120000 config/ags/wallpaper diff --git a/config/ags/.eslintrc.yml b/config/ags/.eslintrc.yml new file mode 100644 index 00000000..1dd5a5b0 --- /dev/null +++ b/config/ags/.eslintrc.yml @@ -0,0 +1,59 @@ +env: + es2022: true +extends: + - eslint:recommended + - plugin:@typescript-eslint/recommended +parser: "@typescript-eslint/parser" +parserOptions: + ecmaVersion: 2022 + sourceType: module + project: ./tsconfig.json + warnOnUnsupportedTypeScriptVersion: false +root: true +ignorePatterns: + - types/ +plugins: + - "@typescript-eslint" +rules: + "@typescript-eslint/ban-ts-comment": + - "off" + "@typescript-eslint/no-non-null-assertion": + - "off" + # "@typescript-eslint/no-explicit-any": + # - "off" + "@typescript-eslint/no-unused-vars": + - error + - varsIgnorePattern: (^unused|_$) + argsIgnorePattern: ^(unused|_) + "@typescript-eslint/no-empty-interface": + - "off" + indent: + - error + - 2 + - SwitchCase: 1 + linebreak-style: + - error + - unix + quotes: + - error + - single + - avoidEscape: true + semi: + - error + - never + no-trailing-spaces: + - error +globals: + pkg: readonly + ags: readonly + ARGV: readonly + imports: readonly + print: readonly + console: readonly + logError: readonly + + App: writable + Utils: writable + Widget: writable + Service: writable + Variable: writable diff --git a/config/ags/apps/settings/bluetooth.ts b/config/ags/apps/settings/bluetooth.ts index d8501dee..26d5cc61 100644 --- a/config/ags/apps/settings/bluetooth.ts +++ b/config/ags/apps/settings/bluetooth.ts @@ -10,11 +10,13 @@ const HpackStartLabel = (label: string) => Widget.Label({ }) const BluetoothToggle = () => Widget.EventBox({ + class_name: "row", child: Widget.Box({ - class_name: "bluetooth_toggle", + class_name: "row", children: [ Widget.Box({ vertical: true, + vpack: "center", hexpand: true, children: [ Widget.Label({ @@ -41,6 +43,9 @@ const BluetoothToggle = () => Widget.EventBox({ }) ] }), + on_primary_click: (self) => { + self.child.children[1]!.activate(); + }, on_secondary_click: (self, event) => { Widget.Menu({ children: [Widget.MenuItem({ @@ -84,15 +89,10 @@ const DeviceMenu = (device: BluetoothDevice) => { const DeviceItem = (device: BluetoothDevice) => Widget.Button({ - class_name: "device", - // on_primary_click: () => { - // if (!connected) - // Utils.execAsync(`nmcli device wifi connect '${access_point.ssid}'`) - // .catch(print); - // else if (is_saved) - // Utils.execAsync(`${App.configDir}/scripts/network.sh --edit ${access_point.ssid}`) - // .catch(print); - // }, + class_name: "row", + on_primary_click: () => { + device.setConnection(!device.connected); + }, on_secondary_click: (self, event) => { DeviceMenu(device)?.popup_at_pointer(event); }, diff --git a/config/ags/apps/settings/main.ts b/config/ags/apps/settings/main.ts index aaf0bb6a..e7a547d4 100644 --- a/config/ags/apps/settings/main.ts +++ b/config/ags/apps/settings/main.ts @@ -1,6 +1,7 @@ import { RegularWindow } from "apps/window"; import { Network } from "./network"; import { Bluetooth } from "./bluetooth"; +import { Wallpapers } from "./wallpapers"; import { Widget as WidgetType } from "types/widgets/widget"; const hyprland = await Service.import("hyprland") import Gtk from "gi://Gtk?version=3.0" @@ -38,7 +39,8 @@ function Settings(cur_tab: string) { transition: "crossfade", children: { "network": Page(Network(), "Network"), - "bluetooth": Page(Bluetooth(), "Bluetooth") + "bluetooth": Page(Bluetooth(), "Bluetooth"), + "wallpaper": Page(Wallpapers(), "Wallpapers") } }) const Row = (name: string, label: string, icon: string = "image-missing") => Widget.Button({ @@ -59,14 +61,16 @@ function Settings(cur_tab: string) { children: [ Row("network", "Network", "network-wireless-signal-excellent-symbolic"), Row("bluetooth", "Bluetooth", "bluetooth-active-symbolic"), - Widget.Separator() + Widget.Separator(), + Row("wallpaper", "Wallpapers", "folder-pictures-symbolic"), + Widget.Separator(), ] }) return Widget.Box({ hexpand: true, vexpand: true, vertical: false, - css: "background-color: #111418", + css: "background-color: @surface", children: [ Widget.Box({ class_name: "full_sidebar", diff --git a/config/ags/apps/settings/network.ts b/config/ags/apps/settings/network.ts index 6e93e2fd..665e831e 100644 --- a/config/ags/apps/settings/network.ts +++ b/config/ags/apps/settings/network.ts @@ -53,7 +53,7 @@ const WifiNetwork = (access_point: AccessPoint) => { const is_saved = saved_networks.value.includes(access_point.ssid!); const connected = access_point.ssid == network.wifi.ssid; return Widget.Button({ - class_name: "wifi_network", + class_name: "row", on_primary_click: () => { if (!connected) Utils.execAsync(`nmcli device wifi connect '${access_point.ssid}'`) @@ -77,6 +77,7 @@ const WifiNetwork = (access_point: AccessPoint) => { // @ts-ignore Widget.Box({ vertical: true, + vpack: "center", children: [ Widget.Label({ class_name: "title", @@ -108,40 +109,46 @@ const WifiNetwork = (access_point: AccessPoint) => { } -const WifiToggle = () => Widget.Box({ - class_name: "wifi_toggle", - children: [ - Widget.Box({ - vertical: true, - hexpand: true, - children: [ - Widget.Label({ - hpack: "start", - class_name: "title", - label: "Wi-Fi" - }), - Widget.Label({ - hpack: "start", - class_name: "description", - label: "Find and connect to Wi-Fi networks" - }) - ] - }), - Widget.Switch({ - vexpand: false, - valign: Gtk.Align.CENTER, - hpack: "end", - on_activate(self) { - timeout(5, () => { - if (network.wifi.enabled != self.active) - network.wifi.enabled = self.active - }) - }, - active: Variable(false, { - poll: [500, () => network.wifi.enabled] - }).bind() - }) - ] +const WifiToggle = () => Widget.EventBox({ + class_name: "row", + child: Widget.Box({ + class_name: "row", + children: [ + Widget.Box({ + vertical: true, + hexpand: true, + children: [ + Widget.Label({ + hpack: "start", + class_name: "title", + label: "Wi-Fi" + }), + Widget.Label({ + hpack: "start", + class_name: "description", + label: "Find and connect to Wi-Fi networks" + }) + ] + }), + Widget.Switch({ + vexpand: false, + valign: Gtk.Align.CENTER, + hpack: "end", + on_activate(self) { + timeout(5, () => { + if (network.wifi.enabled != self.active) + network.wifi.enabled = self.active + }) + }, + active: Variable(false, { + poll: [500, () => network.wifi.enabled] + }).bind() + }) + ] + }), + on_primary_click: self => { + self.child.children[1]!.activate(); + } }) function WifiList() { diff --git a/config/ags/apps/settings/wallpapers.ts b/config/ags/apps/settings/wallpapers.ts new file mode 100644 index 00000000..8397e4b2 --- /dev/null +++ b/config/ags/apps/settings/wallpapers.ts @@ -0,0 +1,226 @@ +import { Variable as VariableType } from "types/variable"; +import { current_wallpaper } from "variables"; + +const GLib = imports.gi.GLib; +const Gio = imports.gi.Gio; + +const changing = Variable(false); +const changing_state = Variable("init"); +const changing_states = { + init: "Initializing...", + changing: "Changing wallpaper...", + colors: "Generating colors...", + tasks: "Waiting for some tasks to finish...", + finish: "Finished!" +}; +Utils.monitorFile("/tmp/wallpaper.status", () => { + Utils.readFileAsync("/tmp/wallpaper.status") + .then(c => { changing_state.setValue(c); }) + .catch(() => { }); +}); +// @ts-ignore +const focused: VariableType = Variable(null); + +function splitListInHalf(arr: T[]): [T[], T[]] { + const midPoint = Math.ceil(arr.length / 2); + const firstPart = arr.slice(0, midPoint); + const secondPart = arr.slice(midPoint); + + return [firstPart, secondPart]; +} + +function listFilesByExtensions(directoryPath: string, extensions: string[]): string[] { + let files: string[] = []; + + let directory = Gio.File.new_for_path(directoryPath); + + let enumerator = directory.enumerate_children( + "standard::*", + Gio.FileQueryInfoFlags.NONE, + null + ); + + let fileInfo; + while ((fileInfo = enumerator.next_file(null)) !== null) { + let fileName = fileInfo.get_name(); + + for (let ext of extensions) { + if (fileName.toLowerCase().endsWith(ext.toLowerCase())) { + files.push(fileName); + break; + } + } + } + + return files; +} + +const Wallpaper = (image: string, name: string) => Widget.Button({ + on_clicked: () => { + focused.setValue(image); + if (!changing.value) { + changing.setValue(true); + Utils.execAsync(`python -O ${GLib.get_home_dir()}/dotfiles/hypr/scripts/wallpaper.py -I ${image}`) + .catch(print) + .finally(() => { changing.setValue(false); }); + } + }, + class_name: "row wallpaper", + setup: self => { + self.hook(focused, () => { + self.toggleClassName("focused", focused.value === image); + }); + }, + hexpand: true, + child: Widget.Box({ + children: [ + Widget.Box({ + hpack: "center", + vpack: "center", + class_name: "image", + setup(self) { + const cache_file = `${GLib.get_home_dir()}/.cache/thumbnails/wallpaper/${name}`; + Utils.readFileAsync(cache_file) + .catch(() => { + Utils.execAsync(`magick ${image} -resize x32 -gravity Center -extent 1:1 ${cache_file}`) + .catch(print); + }); + Utils.idle(() => { + self.css = `background-image: url("${cache_file}");`; + }); + }, + }), + Widget.Box({ + vertical: true, + hexpand: true, + vpack: "center", + children: [ + Widget.Label({ + hpack: "start", + class_name: "title", + label: name, + truncate: "end" + }), + // Widget.Label({ + // hpack: "start", + // class_name: "description", + // label: "Idk" + // }) + ] + }) + ] + }) +}); + +const WallpaperList = () => { + Utils.execAsync(`mkdir -p ${GLib.get_home_dir()}/.cache/thumbnails/wallpaper`) + .then(); + const link_directory = `${App.configDir}/wallpaper`; + const original_directory = `${GLib.get_home_dir()}/Pictures/wallpapers`; + const extensions = [".jpg", ".jpeg", ".png"]; + let fileList = listFilesByExtensions(link_directory, extensions); + let [l_fileList, r_fileList] = splitListInHalf(fileList); + const box = Widget.Box({ + vertical: false, + attribute: { + update: self => { + self.children[0].children! = l_fileList.map(value => Wallpaper(`${original_directory}/${value}`, value)); + self.children[1].children! = r_fileList.map(value => Wallpaper(`${original_directory}/${value}`, value)); + } + }, + children: [ + Widget.Box({ + vertical: true, + children: [] + }), + Widget.Box({ + vertical: true, + children: [] + }), + ] + }); + + Utils.interval(30000, () => { + box.attribute.update(box); + }, box); + + return box; +}; + +export function Wallpapers() { + focused.setValue(current_wallpaper.value); + const box = Widget.Box({ + vertical: true, + children: [ + WallpaperList() + ], + }); + return Widget.Box({ + vertical: true, + children: [ + Widget.Scrollable({ + hscroll: "never", + child: box, + vexpand: true + }), + Widget.Box({ + class_name: "bottom_bar", + vertical: true, + children: [ + Widget.Box({ + class_name: "row", + visible: changing.bind(), + children: [ + Widget.Label({ + class_name: "description", + label: changing_state.bind().as(state => changing_states[state]) + }) + ] + }), + Widget.Box({ + class_name: "actions", + hpack: "end", + children: [ + Widget.Button({ + class_name: "standard_button", + label: "Random", + hpack: "end", + on_clicked: () => { + if (!changing.value) { + changing.setValue(true); + Utils.execAsync(`python -O ${GLib.get_home_dir()}/dotfiles/hypr/scripts/wallpaper.py -R`) + .catch(print) + .finally(() => { changing.setValue(false); }); + } + }, + setup: self => { + self.hook(changing, () => { + self.toggleClassName("disabled", changing.value); + }); + } + }), + Widget.Button({ + class_name: "filled_button", + label: "Select", + hpack: "end", + on_clicked: () => { + if (!changing.value) { + changing.setValue(true); + Utils.execAsync(`python -O ${GLib.get_home_dir()}/dotfiles/hypr/scripts/wallpaper.py -I ${focused.value}`) + .catch(print) + .finally(() => { changing.setValue(false); }); + } + }, + setup: self => { + self.hook(changing, () => { + self.toggleClassName("disabled", changing.value); + }); + } + }) + ] + }) + ] + }) + ] + }) +} diff --git a/config/ags/modules/notificationPopups.ts b/config/ags/modules/notificationPopups.ts index ac07d397..9a62ce3a 100644 --- a/config/ags/modules/notificationPopups.ts +++ b/config/ags/modules/notificationPopups.ts @@ -245,7 +245,7 @@ export function Notifications(monitor = 0) { monitor, name: `notifications${monitor}`, class_name: "notification-popups", - anchor: ["top", "right"], + anchor: ["bottom", "right"], type: Gtk.WindowType.POPUP, child: Widget.Box({ css: "min-width: 2px; min-height: 2px;", diff --git a/config/ags/style-apps.css b/config/ags/style-apps.css index 045af098..ab00cf00 100644 --- a/config/ags/style-apps.css +++ b/config/ags/style-apps.css @@ -27,11 +27,8 @@ font-size: 20px; border-bottom: 1px solid; border-color: @outlineVariant; - /* margin-bottom: 3px; */ -} - -.settings .page_title { color: @onSurfaceVariant; + /* margin-bottom: 3px; */ } .settings .sidebar { @@ -101,107 +98,71 @@ padding: 0px; } -/* Wifi */ - -.settings .wifi_toggle { +.settings .row { padding-left: 16px; padding-right: 16px; padding-top: 12px; - padding-bottom: 8px; + padding-bottom: 12px; + margin: 0px; + border-radius: 0px; } -.settings .wifi_toggle .title { +.settings .row:hover { + background-color: mix(@onSurface, @surface, 0.92) +} + +.settings .row.focused { + background-color: mix(@onSurface, @surface, 0.8) +} + +.settings .row .title { font-weight: normal; font-size: 17px; color: @onSurface } -.settings .wifi_toggle .description { +.settings .row .description { font-weight: normal; font-size: 14px; color: @onSurfaceVariant } -.settings .wifi_list .wifi_network { +.settings .bottom_bar { + background-color: @surface; + font-weight: normal; padding-left: 16px; - padding-right: 16px; - padding-top: 8px; - padding-bottom: 8px; - border-radius: 0px; + padding-top: 6px; + padding-bottom: 6px; + border-top: 1px solid; + border-color: @outlineVariant; } -.settings .wifi_list .wifi_network:hover { - background-color: mix(@onSurface, @surface, 0.92) -} +/* Wifi */ -.settings .wifi_list .wifi_network .title { - font-weight: normal; - font-size: 16px; - color: @onSurface -} - -.settings .wifi_list .wifi_network .description { - font-weight: normal; - font-size: 14px; - color: @onSurfaceVariant -} - -.settings .wifi_list .wifi_network image { +.settings .wifi_list .row image { color: @onSurfaceVariant; margin-right: 16px; } -.settings .wifi_list .wifi_network.active image { +.settings .wifi_list .row.active image { color: @primary; } /* Bluetooth */ -.settings .bluetooth_toggle { - padding-left: 16px; - padding-right: 16px; - padding-top: 12px; - padding-bottom: 8px; -} - -.settings .bluetooth_toggle .title { - font-weight: normal; - font-size: 17px; - color: @onSurface -} - -.settings .bluetooth_toggle .description { - font-weight: normal; - font-size: 14px; - color: @onSurfaceVariant -} - - -.settings .device_list .device { - padding-left: 16px; - padding-right: 16px; - padding-top: 8px; - padding-bottom: 8px; - border-radius: 0px; -} - -.settings .device_list .device:hover { - background-color: mix(@onSurface, @surface, 0.92) -} - -.settings .device_list .device .title { +.settings .device_list .row .title { font-weight: normal; font-size: 16px; color: @onSurface } -.settings .device_list .device .description { +.settings .device_list .row .description { font-weight: normal; font-size: 14px; color: @onSurfaceVariant } -.settings .device_list .device image { +.settings .device_list .row image { color: @onTertiary; background-color: @tertiary; margin-right: 16px; @@ -210,7 +171,18 @@ border-radius: 5px; } -.settings .device_list .device.active image { +.settings .device_list .row.active image { color: @onPrimary; background-color: @primary; } + +/* Theme */ +.settings .wallpaper .image { + border-radius: 7px; + margin-right: 16px; + min-height: 32px; + min-width: 32px; + background-size: cover; + background-position: center; + background-repeat: no-repeat; +} diff --git a/config/ags/style.css b/config/ags/style.css index 4582f6c3..a7b430c4 100644 --- a/config/ags/style.css +++ b/config/ags/style.css @@ -41,7 +41,7 @@ highlight { .corner { background-color: @background; - border-radius: 2px; + border-radius: 38px; } tooltip { @@ -636,7 +636,7 @@ window.notification-popups box.notifications { } .system_scale.backlight { - margin-bottom: 28px; + margin-bottom: 25px; } .system_scale.brightness slider { @@ -818,6 +818,72 @@ window.notification-popups box.notifications { background-color: mix(@onSurfaceVariant, transparent, 0.7); } +/* standard button */ +.standard_button { + border-radius: 100px; + background-color: transparent; + color: @onSurfaceVariant; + padding-left: 24px; + padding-right: 24px; +} + +.standard_button label, .standard_button .icon, +.standard_button .awesome_icon, .standard_button image { + color: @onSurfaceVariant; + margin: 0px; + padding: 0px; +} + +.standard_button:hover { + background-color: mix(@onSurfaceVariant, @surface, 0.8); +} + +.standard_button:active { + background-color: mix(@onSurfaceVariant, @surface, 0.7); +} + +.standard_button.disabled { + background-color: transparent; +} + +.standard_button.disabled label, .standard_button.disabled .icon, +.standard_button.disabled .awesome_icon, .standard_button.disabled image { + color: mix(@onSurface, transparent, 0.38); +} + +/* filled button */ +.filled_button { + border-radius: 100px; + background-color: @primary; + color: @onPrimary; + padding-left: 24px; + padding-right: 24px; +} + +.filled_button label, .filled_button .icon, +.filled_button .awesome_icon, .filled_button image { + color: @onPrimary; + margin: 0px; + padding: 0px; +} + +.filled_button:hover { + background-color: mix(@onPrimary, @primary, 0.92); +} + +.filled_button:active { + background-color: mix(@onPrimary, @primary, 0.8); +} + +.filled_button.disabled { + background-color: mix(@onSurface, @surface, 0.12); + color: mix(@onSurface, @surface, 0.38); +} + +.filled_button.disabled label, .filled_button.disabled .icon, +filled_button.disabled .awesome_icon, .filled_button.disabled image { + color: mix(@onSurface, @surface, 0.38); +} /* ----------------------------------------------------- * Navigation bar diff --git a/config/ags/variables.ts b/config/ags/variables.ts index f2767078..25b84efc 100644 --- a/config/ags/variables.ts +++ b/config/ags/variables.ts @@ -1,5 +1,7 @@ const GLib = imports.gi.GLib; +export const current_wallpaper = Variable(`${GLib.get_home_dir()}/dotfiles/wallpapers/1.jpg`); + export const screen_recorder = Variable(false); export const idle_inhibitor = Variable(false); export const night_light = Variable(false); @@ -13,3 +15,21 @@ export const icons = { 'balanced': ' ', 'power-saver': '󰡵 ' }; + + +const wallpaper_cache_file = `${GLib.get_home_dir()}/.cache/current_wallpaper` +Utils.readFileAsync(wallpaper_cache_file) + .then(out => { current_wallpaper.setValue(out.trim()); }) + .catch(err => { + Utils.writeFileSync(current_wallpaper.value, wallpaper_cache_file) + }); + +Utils.monitorFile( + wallpaper_cache_file, + () => { + Utils.readFileAsync(wallpaper_cache_file) + .then(out => { current_wallpaper.setValue(out); }) + .catch(print); + } +) + diff --git a/config/ags/wallpaper b/config/ags/wallpaper new file mode 120000 index 00000000..43a08017 --- /dev/null +++ b/config/ags/wallpaper @@ -0,0 +1 @@ +/home/sankalp/Pictures/wallpapers \ No newline at end of file