51 Commits

Author SHA1 Message Date
e256dcad2e added some palettes and templates 2026-01-03 03:55:36 +03:00
5b0599a958 changed default kitty config location 2025-12-21 23:39:31 +03:00
afa7275e37 Update README.md 2025-12-20 00:23:34 +03:00
fc5663839e Update README.md 2025-12-20 00:11:15 +03:00
997e7c3eae add pkgbuild 2025-12-19 23:36:21 +03:00
4229db457c merged dev 2025-12-19 23:32:17 +03:00
d17776b8e4 fix: minor ui fixes 2025-12-19 20:04:30 +03:00
8112096647 chore :refactored remaining views 2025-12-19 17:37:42 +03:00
4ada2c44ed chore: refactor 2025-12-19 17:22:23 +03:00
82998d688c build: write .clangd with proper compile_commands path on configure 2025-12-19 10:33:14 +03:00
6ac9c03ec4 fixed linux deps 2025-12-19 10:11:13 +03:00
2a433483d7 Merge branch 'master' into dev 2025-12-19 09:56:18 +03:00
ece7c84371 added cmake presets 2025-12-19 09:55:29 +03:00
5b641cdd02 fix: typo in font_loader.windows 2025-12-19 08:21:37 +03:00
dff3e916fe bump version 2025-12-19 00:23:02 +03:00
2d653834a5 fix(nixos): write to config.temp.toml if config.toml is unwriteable 2025-12-19 00:19:26 +03:00
9be0a159ea fixed limux build 2025-12-18 23:53:06 +03:00
0288773ccb revert removed deps 2025-12-18 23:33:04 +03:00
c68ca3dabe wip: moving backend-related stuff out of the app logic 2025-12-18 16:45:49 +03:00
292a748ac4 chore: minor adjustments 2025-12-18 14:57:15 +03:00
7641846600 chore: structured src/gui, run clang-format 2025-12-18 13:23:50 +03:00
613c2c80f5 build: fix msvc builds 2025-12-18 11:51:28 +03:00
1a1747a472 chore: got build working on mac (kind of) 2025-12-18 01:29:32 +03:00
57c3c55a94 bump version 2025-12-18 00:45:10 +03:00
d4ff415f45 fix: gtk dialogs freezing 2025-12-18 00:42:47 +03:00
4c0502d8ee fix missing XDG_DATA_DIRS on NixOS 2025-12-18 00:11:55 +03:00
0acb36445f adjusted default theme 2025-12-17 16:13:14 +03:00
b08ba4d754 fix: coloring 2025-12-17 15:49:48 +03:00
231e9f0176 updated preview 2025-12-17 14:46:32 +03:00
b98761a172 chore: fixed build deps 2025-12-17 13:42:48 +03:00
92b06a9e0c bump version 2025-12-17 13:33:25 +03:00
019b0db522 build: added gtk dep 2025-12-17 13:32:26 +03:00
58eff4d97e chore: cleanup the ui 2025-12-17 13:14:46 +03:00
b4ca5e1912 feat: autocomplete in template editor 2025-12-17 11:45:46 +03:00
899a5d50c4 removed eyedropper for now 2025-12-17 10:45:35 +03:00
2813a8bd05 feat: added eyedropper 2025-12-17 10:21:33 +03:00
e6bac8e220 feat: init palettes with default colorscheme to avoid messed up UI 2025-12-17 09:50:14 +03:00
5bb8a687ea fix: added delete confirmation dialog in color_scheme_editor 2025-12-17 08:37:15 +03:00
10516212bf fix (fonts): load exact match 2025-12-17 08:32:56 +03:00
89888adf8d chore: add doc link 2025-12-17 03:11:15 +03:00
c58ff17289 feat: font selector 2025-12-17 03:06:24 +03:00
ef0854aa39 fix: normalize paths 2025-12-17 02:58:23 +03:00
1c2486d476 feat: allow to remove templates 2025-12-17 02:49:52 +03:00
d4c563f585 refactor: error handling with err objects 2025-12-17 02:25:21 +03:00
f7c290110e chore: split color_scheme_editor 2025-12-17 01:41:44 +03:00
659c5f28e5 versioning 2025-12-16 00:37:18 +03:00
cd817446b0 versioning (WIP) 2025-12-15 23:46:47 +03:00
a5d6503305 set version in flake 2025-12-15 21:10:23 +03:00
8a2b224fd3 set git version 2025-12-15 20:55:54 +03:00
4b4af0f8fe updated test flake workflow 2025-12-15 13:23:31 +03:00
d40b436461 updated readme 2025-12-15 13:22:29 +03:00
138 changed files with 7628 additions and 2358 deletions

View File

@@ -2,7 +2,7 @@ name: Test PKGBUILD-git
on:
push:
branch: master
branches: master
pull_request:
branches: master

View File

@@ -2,8 +2,9 @@ name: Test flake.nix
on:
push:
branches: [master]
branches: master
pull_request:
branches: master
jobs:
build:

View File

@@ -49,7 +49,8 @@ jobs:
sudo apt-get update
sudo apt-get install -y cmake build-essential git \
libglfw3-dev libfreetype6-dev libfontconfig1-dev \
libx11-dev libxrandr-dev libxi-dev \
zlib1g-dev libharfbuzz-dev \
libx11-dev libxrandr-dev libxi-dev libgtk-3-dev \
mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev \
libxinerama-dev libxcursor-dev libxkbcommon-dev
@@ -83,10 +84,11 @@ jobs:
run: |
dnf install -y cmake gcc gcc-c++ make rpm-build git \
glfw-devel freetype-devel fontconfig-devel \
zlib-devel harfbuzz-devel \
libX11-devel libXrandr-devel libXi-devel \
mesa-libGL-devel mesa-libGLU-devel \
libXinerama-devel libXcursor-devel \
wayland-devel wayland-protocols-devel
wayland-devel wayland-protocols-devel gtk3-devel
- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_GLFW=ON

3
.gitignore vendored
View File

@@ -3,7 +3,10 @@
.vs
out
.clangd
build/
build-msvc/
CMakeCache.txt
CMakeFiles/
cmake_install.cmake

35
.vscode/launch.json vendored
View File

@@ -1,19 +1,12 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug current target",
"name": "Debug current target (GDB)",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [
"--apply",
"--theme",
"dark"
],
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
@@ -32,5 +25,29 @@
}
]
},
{
"name": "Debug current target (LLDB)",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"miDebuggerPath": "lldb"
},
{
"name": "Debug current target (MSVC)",
"type": "cppvsdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal"
}
]
}

3
.vscode/settnigs.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"cmake.useCMakePresets": "always"
}

View File

@@ -1,6 +1,6 @@
# Maintainer: Daniel Dada <dan@binarygoose.dev>
pkgname=clrsync
pkgver=0.1.4
pkgver=1.0.1
pkgrel=1
pkgdesc="Color scheme manager"
arch=('x86_64')
@@ -14,6 +14,7 @@ depends=(
mesa
libglvnd
libxcursor
gtk3
)
makedepends=(
@@ -26,6 +27,7 @@ makedepends=(
libxcursor
wayland
wayland-protocols
gtk3
)
source=("$pkgname-$pkgver.tar.gz::https://github.com/obsqrbtz/clrsync/archive/refs/tags/v$pkgver.tar.gz")

View File

@@ -1,6 +1,6 @@
# Maintainer: Daniel Dada <dan@binarygoose.dev>
pkgname=clrsync-git
pkgver=r22.d8baae2
pkgver=r107.4229db4
pkgrel=1
pkgdesc="Color scheme manager (git version)"
arch=('x86_64')
@@ -10,9 +10,12 @@ depends=(
glfw
freetype2
fontconfig
zlib
harfbuzz
mesa
libglvnd
libxcursor
gtk3
)
makedepends=(
@@ -26,6 +29,7 @@ makedepends=(
libxcursor
wayland
wayland-protocols
gtk3
)
provides=('clrsync')
conflicts=('clrsync')

View File

@@ -14,6 +14,7 @@ depends=(
mesa
libglvnd
libxcursor
gtk3
)
makedepends=(
@@ -26,6 +27,7 @@ makedepends=(
libxcursor
wayland
wayland-protocols
gtk3
)
source=("$pkgname-$pkgver.tar.gz::https://github.com/obsqrbtz/clrsync/archive/refs/tags/v$pkgver.tar.gz")

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
project(clrsync VERSION 0.1.4 LANGUAGES CXX)
project(clrsync VERSION 1.0.1 LANGUAGES CXX)
include(GNUInstallDirs)
@@ -10,6 +10,9 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
file(WRITE "${CMAKE_SOURCE_DIR}/.clangd"
"CompileFlags:\n CompilationDatabase: ${CMAKE_BINARY_DIR}\n")
option(USE_SYSTEM_GLFW "Use system-installed GLFW instead of fetching it statically" OFF)
message(STATUS "USE_SYSTEM_GLFW: ${USE_SYSTEM_GLFW}")
@@ -26,9 +29,45 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
if(DEFINED CLRSYNC_SEMVER)
set(SEMVER "${CLRSYNC_SEMVER}")
else()
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git describe --tags --long --always
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
if(GIT_DESCRIBE MATCHES "^[vV]?[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+-g[0-9a-f]+")
string(REGEX REPLACE
"^[vV]?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-g([0-9a-f]+)"
"\\1+git.g\\3"
SEMVER "${GIT_DESCRIBE}"
)
elseif(GIT_DESCRIBE)
set(SEMVER "${PROJECT_VERSION}.git.${GIT_DESCRIBE}")
else()
set(SEMVER "${PROJECT_VERSION}")
endif()
endif()
message(STATUS "clrsync version: ${SEMVER}")
configure_file(
${CMAKE_SOURCE_DIR}/src/core/version.hpp.in
${CMAKE_SOURCE_DIR}/src/core/version.hpp
${CMAKE_SOURCE_DIR}/src/core/common/version.hpp.in
${CMAKE_SOURCE_DIR}/src/core/common/version.hpp
@ONLY
)
configure_file(
${CMAKE_SOURCE_DIR}/VERSION.in
${CMAKE_SOURCE_DIR}/VERSION
@ONLY
)

325
CMakePresets.json Normal file
View File

@@ -0,0 +1,325 @@
{
"version": 6,
"configurePresets": [
{
"name": "base",
"hidden": true
},
{
"name": "debug",
"hidden": true,
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"hidden": true,
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux",
"hidden": true,
"inherits": "base",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
},
{
"name": "windows",
"hidden": true,
"inherits": "base",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "macos",
"hidden": true,
"inherits": "base",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "gcc",
"hidden": true,
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++"
}
},
{
"name": "clang",
"hidden": true,
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
}
},
{
"name": "ninja",
"hidden": true,
"generator": "Ninja"
},
{
"name": "make",
"hidden": true,
"generator": "Unix Makefiles"
},
{
"name": "msvc-ninja",
"displayName": "MSVC (Ninja)",
"generator": "Ninja",
"hidden": true,
"binaryDir": "${sourceDir}/build/windows/msvc",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
}
},
{
"name": "msvc-vs2026",
"displayName": "MSVC (Visual Studio 18 2026)",
"generator": "Visual Studio 18 2026",
"binaryDir": "${sourceDir}/build/windows/msvc/vs2026",
"architecture": {
"value": "x64"
}
},
{
"name": "windows-msvc-ninja-debug",
"inherits": [
"windows",
"msvc-ninja",
"ninja",
"debug"
],
"displayName": "Windows · MSVC · Ninja · Debug",
"binaryDir": "${sourceDir}/build/windows/msvc/ninja/debug"
},
{
"name": "windows-msvc-ninja-release",
"inherits": [
"windows",
"msvc-ninja",
"ninja",
"release"
],
"displayName": "Windows · MSVC · Ninja · Release",
"binaryDir": "${sourceDir}/build/windows/msvc/ninja/release"
},
{
"name": "linux-gcc-ninja-debug",
"inherits": [
"linux",
"gcc",
"ninja",
"debug"
],
"displayName": "Linux · GCC · Ninja · Debug",
"binaryDir": "${sourceDir}/build/linux/gcc/ninja/debug"
},
{
"name": "linux-gcc-ninja-release",
"inherits": [
"linux",
"gcc",
"ninja",
"release"
],
"displayName": "Linux · GCC · Ninja · Release",
"binaryDir": "${sourceDir}/build/linux/gcc/ninja/release"
},
{
"name": "linux-gcc-make-debug",
"inherits": [
"linux",
"gcc",
"make",
"debug"
],
"displayName": "Linux · GCC · Make · Debug",
"binaryDir": "${sourceDir}/build/linux/gcc/make/debug"
},
{
"name": "linux-gcc-make-release",
"inherits": [
"linux",
"gcc",
"make",
"release"
],
"displayName": "Linux · GCC · Make · Release",
"binaryDir": "${sourceDir}/build/linux/gcc/make/release"
},
{
"name": "linux-clang-ninja-debug",
"inherits": [
"linux",
"clang",
"ninja",
"debug"
],
"displayName": "Linux · Clang · Ninja · Debug",
"binaryDir": "${sourceDir}/build/linux/clang/ninja/debug"
},
{
"name": "linux-clang-ninja-release",
"inherits": [
"linux",
"clang",
"ninja",
"release"
],
"displayName": "Linux · Clang · Ninja · Release",
"binaryDir": "${sourceDir}/build/linux/clang/ninja/release"
},
{
"name": "linux-clang-make-debug",
"inherits": [
"linux",
"clang",
"make",
"debug"
],
"displayName": "Linux · Clang · Make · Debug",
"binaryDir": "${sourceDir}/build/linux/clang/make/debug"
},
{
"name": "linux-clang-make-release",
"inherits": [
"linux",
"clang",
"make",
"release"
],
"displayName": "Linux · Clang · Make · Release",
"binaryDir": "${sourceDir}/build/linux/clang/make/release"
},
{
"name": "macos-appleclang-ninja-debug",
"inherits": [
"macos",
"clang",
"ninja",
"debug"
],
"displayName": "macOS · Apple Clang · Ninja · Debug",
"binaryDir": "${sourceDir}/build/macos/appleclang/ninja/debug"
},
{
"name": "macos-appleclang-ninja-release",
"inherits": [
"macos",
"clang",
"ninja",
"release"
],
"displayName": "macOS · Apple Clang · Ninja · Release",
"binaryDir": "${sourceDir}/build/macos/appleclang/ninja/release"
},
{
"name": "macos-appleclang-make-debug",
"inherits": [
"macos",
"clang",
"make",
"debug"
],
"displayName": "macOS · Apple Clang · Make · Debug",
"binaryDir": "${sourceDir}/build/macos/appleclang/make/debug"
},
{
"name": "macos-appleclang-make-release",
"inherits": [
"macos",
"clang",
"make",
"release"
],
"displayName": "macOS · Apple Clang · Make · Release",
"binaryDir": "${sourceDir}/build/macos/appleclang/make/release"
}
],
"buildPresets": [
{
"name": "vs-debug",
"configurePreset": "msvc-vs2026",
"configuration": "Debug"
},
{
"name": "vs-release",
"configurePreset": "msvc-vs2026",
"configuration": "Release"
},
{
"name": "msvc-ninja-debug",
"configurePreset": "windows-msvc-ninja-debug",
"configuration": "Debug"
},
{
"name": "msvc-ninja-release",
"configurePreset": "windows-msvc-ninja-release",
"configuration": "Release"
},
{
"name": "linux-gcc-ninja-debug",
"configurePreset": "linux-gcc-ninja-debug"
},
{
"name": "linux-gcc-ninja-release",
"configurePreset": "linux-gcc-ninja-release"
},
{
"name": "linux-gcc-make-debug",
"configurePreset": "linux-gcc-make-debug"
},
{
"name": "linux-gcc-make-release",
"configurePreset": "linux-gcc-make-release"
},
{
"name": "linux-clang-ninja-debug",
"configurePreset": "linux-clang-ninja-debug"
},
{
"name": "linux-clang-ninja-release",
"configurePreset": "linux-clang-ninja-release"
},
{
"name": "linux-clang-make-debug",
"configurePreset": "linux-clang-make-debug"
},
{
"name": "linux-clang-make-release",
"configurePreset": "linux-clang-make-release"
},
{
"name": "macos-appleclang-ninja-debug",
"configurePreset": "macos-appleclang-ninja-debug"
},
{
"name": "macos-appleclang-ninja-release",
"configurePreset": "macos-appleclang-ninja-release"
},
{
"name": "macos-appleclang-make-debug",
"configurePreset": "macos-appleclang-make-debug"
},
{
"name": "macos-appleclang-make-release",
"configurePreset": "macos-appleclang-make-release"
}
]
}

View File

@@ -3,22 +3,24 @@
# clrsync
**Notice:** This application is not yet released and is subject to change.
Deb, RPM, and AUR packages, as well as a Windows installer, will be available soon.
A theme management tool for synchronizing color schemes across multiple applications. clrsync allows to define color palettes once and apply them consistently to all configurable applications.
![Preview](assets/screenshot.png)
## Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Linux](#linux)
- [Ubuntu](#ubuntu)
- [Fedora](#fedora)
- [NixOS](#nixos)
- [Home Manager Module](#home-manager-module)
- [Package](#package)
- [Install to profile](#install-to-profile)
- [Run without installing](#run-without-installing)
- [Windows](#windows)
- [Other systems](#other-systems)
- [Building](#building)
- [Prerequisites](#prerequisites)
@@ -30,6 +32,7 @@ A theme management tool for synchronizing color schemes across multiple applicat
- [Usage](#usage)
- [CLI](#cli)
- [GUI](#gui)
- [Extras](#extras)
- [Acknowledgments](#acknowledgments)
## Features
@@ -41,7 +44,40 @@ A theme management tool for synchronizing color schemes across multiple applicat
## Installation
### NixOS
### Linux
#### Arch Linux
Install the package from AUR using any helper or install manually
```shell
yay -S clrsync-git
```
#### Ubuntu
1. Download the latest .deb from the [releases page](https://github.com/obsqrbtz/clrsync/releases)
2. Install the package
```shell
sudo dpkg -i clrsync-<version>.deb
```
#### Fedora
1. Download the latest .rpm from the [releases page](https://github.com/obsqrbtz/clrsync/releases)
2. Install the package
```shell
sudo rpm -i clrsync-<version>.rpm
# or
sudo dnf install clrsync-<version>.rpm
```
#### NixOS
<details>
<summary>Home Manager Module</summary>
@@ -198,6 +234,12 @@ nix run github:obsqrbtz/clrsync#clrsync-cli
</details>
### Windows
1. Download the latest installer from the [releases page](https://github.com/obsqrbtz/clrsync/releases)
2. Run the installer and follow the wizard
3. Optionally, add the installation dir to your PATH for easier CLI access
### Other systems
Follow the steps from Building section then install with cmake:
@@ -422,6 +464,10 @@ The GUI provides:
- **Template Editor**: Edit template files
- **Live Preview**: See changes in real-time
## Extras
You may find some pre-configured color schemes and templates in [extra](extra) directory of this repository.
## Acknowledgments
- **[matugen](https://github.com/InioX/matugen)** - A material you color generation tool
@@ -430,4 +476,3 @@ The GUI provides:
- **[toml++](https://github.com/marzer/tomlplusplus)** - Header-only TOML config file parser and serializer for C++17
- **[argparse](https://github.com/p-ranav/argparse)** - Argument Parser for Modern C++
- **[ImGuiColorTextEdit](https://github.com/BalazsJako/ImGuiColorTextEdit)** - Syntax highlighting text editor for ImGui
- **cursed** by **[pyratebeard](https://pyratebeard.net)** - Color scheme

1
VERSION Normal file
View File

@@ -0,0 +1 @@
1.0.1

1
VERSION.in Normal file
View File

@@ -0,0 +1 @@
@PROJECT_VERSION@

Binary file not shown.

Before

Width:  |  Height:  |  Size: 370 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@@ -7,7 +7,19 @@ if(WIN32)
freetype
URL https://download.savannah.gnu.org/releases/freetype/freetype-2.14.1.tar.gz
)
FetchContent_MakeAvailable(freetype)
elseif(APPLE)
option(USE_SYSTEM_GLFW ON)
find_package(Freetype REQUIRED)
find_package(ZLIB REQUIRED)
find_package(BZip2 REQUIRED)
find_package(PNG REQUIRED)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(HARFBUZZ harfbuzz)
endif()
else()
find_package(Freetype REQUIRED)
find_package(PkgConfig REQUIRED)
@@ -15,17 +27,31 @@ else()
find_package(ZLIB REQUIRED)
find_package(BZip2 REQUIRED)
find_package(PNG REQUIRED)
find_library(BROTLIDEC_LIBRARY NAMES brotlidec)
find_library(BROTLICOMMON_LIBRARY NAMES brotlicommon)
pkg_check_modules(HARFBUZZ harfbuzz)
pkg_check_modules(WAYLAND_CLIENT wayland-client)
pkg_check_modules(WAYLAND_EGL wayland-egl)
endif()
if(LINUX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
endif()
if(USE_SYSTEM_GLFW)
if(APPLE)
find_package(glfw3 QUIET)
if(glfw3_FOUND)
set(GLFW_FOUND TRUE)
set(GLFW_LIBRARIES glfw)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLFW REQUIRED glfw3)
endif()
else()
pkg_check_modules(GLFW REQUIRED glfw3)
endif()
else()
include(FetchContent)
FetchContent_Declare(
@@ -50,18 +76,19 @@ if(BROTLIDEC_LIBRARY AND BROTLICOMMON_LIBRARY)
list(APPEND FREETYPE_EXTRA_LIBS ${BROTLIDEC_LIBRARY} ${BROTLICOMMON_LIBRARY})
message(STATUS "Found Brotli libraries")
endif()
if(HARFBUZZ_FOUND)
list(APPEND FREETYPE_EXTRA_LIBS ${HARFBUZZ_LIBRARIES})
message(STATUS "Found HarfBuzz")
endif()
set(WAYLAND_LIBS "")
if(WAYLAND_CLIENT_FOUND)
if(NOT APPLE)
if(WAYLAND_CLIENT_FOUND)
list(APPEND WAYLAND_LIBS ${WAYLAND_CLIENT_LIBRARIES})
message(STATUS "Found Wayland client")
endif()
if(WAYLAND_EGL_FOUND)
endif()
if(WAYLAND_EGL_FOUND)
list(APPEND WAYLAND_LIBS ${WAYLAND_EGL_LIBRARIES})
message(STATUS "Found Wayland EGL")
endif()
endif()

View File

@@ -27,7 +27,7 @@ set(CPACK_NSIS_CREATE_DESKTOP_LINKS "bin/clrsync_gui.exe;clrsync")
# Debian
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Daniel Dada <dan@binarygoose.dev>")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.31), libglfw3, libfreetype6")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.31), libglfw3, libfreetype6, zlib1g, libharfbuzz0b")
set(CPACK_DEBIAN_PACKAGE_SECTION "utils")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
@@ -36,6 +36,6 @@ set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
set(CPACK_RPM_PACKAGE_GROUP "Applications/System")
set(CPACK_RPM_PACKAGE_URL "https://github.com/obsqrbtz/clrsync")
set(CPACK_RPM_PACKAGE_REQUIRES "freetype, glfw, fontconfig")
set(CPACK_RPM_PACKAGE_REQUIRES "freetype, glfw, fontconfig, zlib, harfbuzz")
include(CPack)

View File

@@ -1,5 +1,5 @@
[general]
default_theme = 'cursed'
default_theme = 'dark'
palettes_path = '~/.config/clrsync/palettes'
font = 'JetBrainsMono Nerd Font Mono'
font_size = 14
@@ -12,7 +12,7 @@ output_path = '~/.config/clrsync/formats-demo'
[templates.kitty]
enabled = true
input_path = '~/.config/clrsync/templates/kitty.conf'
output_path = '~/.config/kitty/kitty_test.conf'
output_path = '~/.config/kitty/clrsync.conf'
reload_cmd = 'pkill -SIGUSR1 kitty'
[templates.nvim]

View File

@@ -1,67 +0,0 @@
[colors]
# General
background = "#f5f5f5FF"
on_background = "#3d3d2fFF"
surface = "#e8e8e8FF"
on_surface = "#3d3d2fFF"
surface_variant = "#d0d0c8FF"
on_surface_variant = "#3d3d2fFF"
border_focused = "#c9a305FF"
border = "#d0d0c8FF"
foreground = "#3d3d2fFF"
cursor = "#c9a305FF"
accent = "#b44242FF"
# Terminal
base00 = "#f5f5f5FF"
base01 = "#b44242FF"
base02 = "#95a328FF"
base03 = "#c9a305FF"
base04 = "#60928fFF"
base05 = "#7c435aFF"
base06 = "#a48b4aFF"
base07 = "#3d3d2fFF"
base08 = "#c0c0b8FF"
base09 = "#dc7671FF"
base0A = "#d4d430FF"
base0B = "#9e9052FF"
base0C = "#76c39bFF"
base0D = "#86596cFF"
base0E = "#b89a1fFF"
base0F = "#4f4f48FF"
# Semantic
success = "#95a328FF"
info = "#60928fFF"
warning = "#c9a305FF"
error = "#b44242FF"
on_success = "#f5f5f5FF"
on_info = "#f5f5f5FF"
on_warning = "#f5f5f5FF"
on_error = "#f5f5f5FF"
# Code editor
editor_background = "#f5f5f5FF"
editor_command = "#b89a1fFF"
editor_comment = "#a0a098FF"
editor_disabled = "#c0c0b8FF"
editor_emphasis = "#dc7671FF"
editor_error = "#b44242FF"
editor_inactive = "#a0a098FF"
editor_line_number = "#86596cFF"
editor_link = "#60928fFF"
editor_main = "#3d3d2fFF"
editor_selected = "#d0d0c8FF"
editor_selection_inactive = "#e0e0d8FF"
editor_string = "#5fa37bFF"
editor_success = "#95a328FF"
editor_warning = "#c9a305FF"
[general]
name = 'cursed-light'

View File

@@ -0,0 +1,54 @@
[colors]
accent = '#9A8652FF'
background = '#111111FF'
base00 = '#111111FF'
base01 = '#668A51FF'
base02 = '#9A8652FF'
base03 = '#B47837FF'
base04 = '#9A5552FF'
base05 = '#AA477BFF'
base06 = '#3A898CFF'
base07 = '#B5B5B5FF'
base08 = '#AA4E4AFF'
base09 = '#A9DC86FF'
base0A = '#B6AB82FF'
base0B = '#C5916BFF'
base0C = '#AC7676FF'
base0D = '#B0779EFF'
base0E = '#849899FF'
base0F = '#D2D2D2FF'
border = '#242424FF'
border_focused = '#2E2E2EFF'
cursor = '#D2D2D2FF'
editor_background = '#111111FF'
editor_command = '#3A898CFF'
editor_comment = '#849899FF'
editor_disabled = '#849899FF'
editor_emphasis = '#A9DC86FF'
editor_error = '#AA4E4AFF'
editor_inactive = '#849899FF'
editor_line_number = '#849899FF'
editor_link = '#B0779EFF'
editor_main = '#D2D2D2FF'
editor_selected = '#242424FF'
editor_selection_inactive = '#1D1C1CFF'
editor_string = '#9A8652FF'
editor_success = '#668A51FF'
editor_warning = '#B47837FF'
error = '#AA4E4AFF'
foreground = '#D2D2D2FF'
info = '#3A898CFF'
on_background = '#D4D4D4FF'
on_error = '#D2D2D2FF'
on_info = '#D2D2D2FF'
on_success = '#D2D2D2FF'
on_surface = '#D4D4D4FF'
on_surface_variant = '#D4D4D4FF'
on_warning = '#D2D2D2FF'
success = '#668A51FF'
surface = '#111111FF'
surface_variant = '#191919FF'
warning = '#B47837FF'
[general]
name = 'dark'

View File

@@ -0,0 +1,54 @@
[colors]
accent = '#9A8652FF'
background = '#E0E0E0FF'
base00 = '#E0E0E0FF'
base01 = '#668A51FF'
base02 = '#9A8652FF'
base03 = '#B47837FF'
base04 = '#9A5552FF'
base05 = '#AA477BFF'
base06 = '#3A898CFF'
base07 = '#5A5A5AFF'
base08 = '#AA4E4AFF'
base09 = '#4A7A2EFF'
base0A = '#7A6A42FF'
base0B = '#A5714BFF'
base0C = '#8C5656FF'
base0D = '#90577EFF'
base0E = '#2A6A6DFF'
base0F = '#2A2A2AFF'
border = '#C5C5C5FF'
border_focused = '#B9B9B9FF'
cursor = '#2A2A2AFF'
editor_background = '#E0E0E0FF'
editor_command = '#3A898CFF'
editor_comment = '#849899FF'
editor_disabled = '#A0A0A0FF'
editor_emphasis = '#4A7A2EFF'
editor_error = '#AA4E4AFF'
editor_inactive = '#A0A0A0FF'
editor_line_number = '#9A9A95FF'
editor_link = '#90577EFF'
editor_main = '#2A2A2AFF'
editor_selected = '#C9C9C9FF'
editor_selection_inactive = '#D2D2D2FF'
editor_string = '#9A8652FF'
editor_success = '#668A51FF'
editor_warning = '#B47837FF'
error = '#AA4E4AFF'
foreground = '#2A2A2AFF'
info = '#3A898CFF'
on_background = '#2A2A2AFF'
on_error = '#FAFAF8FF'
on_info = '#FAFAF8FF'
on_success = '#FAFAF8FF'
on_surface = '#2A2A2AFF'
on_surface_variant = '#3A3A3AFF'
on_warning = '#FAFAF8FF'
success = '#668A51FF'
surface = '#E0E0E0FF'
surface_variant = '#CECECEFF'
warning = '#B47837FF'
[general]
name = 'light'

105
extra/README.md Normal file
View File

@@ -0,0 +1,105 @@
# Extras
## Palettes
### Cursed
A dark color scheme, which tries to be like `cursed` theme by **[pyratebeard](https://pyratebeard.net)**
![cursed](img/cursed.png)
### Cursed-light
Same as `cursed`, but it also tries to be light as well
![cursed-light](img/cursed-light.png)
### Nord
Color scheme based on `Nord`
![nord](img/nord.png)
## Pre-configured templates
### Kitty
**1. Download [template file](templates/kitty.conf)**
**2. Configure template in `~/.config/clrsync/config.toml`**
```toml
[templates.kitty]
enabled = true
input_path = '~/.config/clrsync/templates/kitty.conf'
output_path = '~/.config/kitty/clrsync.conf'
reload_cmd = 'pkill -SIGUSR1 kitty'
```
**3. Import generated color scheme in `~/.config/kitty/kitty.conf**
```conf
include clrsync.conf
```
### Neovim
**1. Download [template file](templates/nvim.lua)**
**2. Configure template in `~/.config/clrsync/config.toml`**
```toml
[templates.nvim]
enabled = true
input_path = '~/.config/clrsync/templates/nvim.lua'
output_path = '~/.config/nvim/colors/clrsync.lua'
reload_cmd = ''
```
**3. Set colorscheme in neovim config**
```lua
vim.cmd.colorscheme 'clrsync'
```
### Alacritty
**1. Download [template file](templates/alacritty.toml)**
**2. Configure template in `~/.config/clrsync/config.toml`**
```toml
[templates.alacritty]
enabled = true
input_path = '~/.config/clrsync/templates/alacritty.toml'
output_path = '~/.config/alacritty/clrsync.toml'
reload_cmd = ''
```
**3. Import generated color scheme in `~/.config/alacritty/alacritty.toml**
```toml
[general]
import = ["clrsync.toml"]
```
### Ghostty
**1. Download [template file](templates/ghostty)**
**2. Configure template in `~/.config/clrsync/config.toml`**
```toml
[templates.ghostty]
enabled = true
input_path = '~/.config/clrsync/templates/ghostty'
output_path = '~/.config/ghostty/themes/clrsync'
reload_cmd = 'pkill -SIGUSR2 ghostty'
```
**3. Set generated color scheme in `~/.config/ghostty/config**
```toml
theme = "clrsync"
```

BIN
extra/img/cursed-light.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 KiB

BIN
extra/img/cursed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB

BIN
extra/img/nord.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 KiB

View File

@@ -0,0 +1,54 @@
[colors]
accent = '#95A328FF'
background = '#F5F5F5FF'
base00 = '#F5F5F5FF'
base01 = '#B44242FF'
base02 = '#95A328FF'
base03 = '#C9A305FF'
base04 = '#60928FFF'
base05 = '#7C435AFF'
base06 = '#A48B4AFF'
base07 = '#3D3D2FFF'
base08 = '#C0C0B8FF'
base09 = '#DC7671FF'
base0A = '#D4D430FF'
base0B = '#9E9052FF'
base0C = '#76C39BFF'
base0D = '#86596CFF'
base0E = '#B89A1FFF'
base0F = '#4F4F48FF'
border = '#D0D0C8FF'
border_focused = '#C9A305FF'
cursor = '#C9A305FF'
editor_background = '#F5F5F5FF'
editor_command = '#B89A1FFF'
editor_comment = '#A0A098FF'
editor_disabled = '#C0C0B8FF'
editor_emphasis = '#DC7671FF'
editor_error = '#B44242FF'
editor_inactive = '#A0A098FF'
editor_line_number = '#86596CFF'
editor_link = '#60928FFF'
editor_main = '#3D3D2FFF'
editor_selected = '#D0D0C8FF'
editor_selection_inactive = '#E0E0D8FF'
editor_string = '#5FA37BFF'
editor_success = '#95A328FF'
editor_warning = '#C9A305FF'
error = '#B44242FF'
foreground = '#3D3D2FFF'
info = '#60928FFF'
on_background = '#3D3D2FFF'
on_error = '#F5F5F5FF'
on_info = '#F5F5F5FF'
on_success = '#F5F5F5FF'
on_surface = '#3D3D2FFF'
on_surface_variant = '#CCCCCCFF'
on_warning = '#F5F5F5FF'
success = '#95A328FF'
surface = '#E8E8E8FF'
surface_variant = '#D0D0C8FF'
warning = '#C9A305FF'
[general]
name = 'cursed-light'

View File

@@ -1,5 +1,5 @@
[colors]
accent = '#B44242FF'
accent = '#95A328FF'
background = '#151515FF'
base00 = '#151515FF'
base01 = '#B44242FF'
@@ -22,7 +22,7 @@ border_focused = '#E1C135FF'
cursor = '#E1C135FF'
editor_background = '#151515FF'
editor_command = '#CEB34FFF'
editor_comment = '#3F3639FF'
editor_comment = '#7A7A7AFF'
editor_disabled = '#3F3639FF'
editor_emphasis = '#DC7671FF'
editor_error = '#B44242FF'
@@ -43,7 +43,7 @@ on_error = '#151515FF'
on_info = '#151515FF'
on_success = '#151515FF'
on_surface = '#C2C2B0FF'
on_surface_variant = '#C2C2B0FF'
on_surface_variant = '#CCCCCCFF'
on_warning = '#151515FF'
success = '#95A328FF'
surface = '#1C1C1CFF'

54
extra/palettes/nord.toml Normal file
View File

@@ -0,0 +1,54 @@
[colors]
accent = '#A1CDFAFF'
background = '#2E3440FF'
base00 = '#2E3440FF'
base01 = '#BF616AFF'
base02 = '#A3BE8CFF'
base03 = '#EBCB8BFF'
base04 = '#81A1C1FF'
base05 = '#B48EADFF'
base06 = '#88C0D0FF'
base07 = '#E5E9F0FF'
base08 = '#4C566AFF'
base09 = '#D08770FF'
base0A = '#EBCB8BFF'
base0B = '#A3BE8CFF'
base0C = '#8FBCBBFF'
base0D = '#5E81ACFF'
base0E = '#B48EADFF'
base0F = '#ECEFF4FF'
border = '#4C566AFF'
border_focused = '#88C0D0FF'
cursor = '#D8DEE9FF'
editor_background = '#2E3440FF'
editor_command = '#81A1C1FF'
editor_comment = '#616E88FF'
editor_disabled = '#4C566AFF'
editor_emphasis = '#B48EADFF'
editor_error = '#BF616AFF'
editor_inactive = '#616E88FF'
editor_line_number = '#4C566AFF'
editor_link = '#88C0D0FF'
editor_main = '#D8DEE9FF'
editor_selected = '#434C5EFF'
editor_selection_inactive = '#3B4252FF'
editor_string = '#A3BE8CFF'
editor_success = '#A3BE8CFF'
editor_warning = '#EBCB8BFF'
error = '#BF616AFF'
foreground = '#D8DEE9FF'
info = '#5E81ACFF'
on_background = '#D8DEE9FF'
on_error = '#2E3440FF'
on_info = '#2E3440FF'
on_success = '#2E3440FF'
on_surface = '#ECEFF4FF'
on_surface_variant = '#ECEFF4FF'
on_warning = '#2E3440FF'
success = '#A3BE8CFF'
surface = '#3B4252FF'
surface_variant = '#434C5EFF'
warning = '#EBCB8BFF'
[general]
name = 'nord'

View File

@@ -0,0 +1,69 @@
[colors.primary]
background = '{background}'
foreground = '{foreground}'
[colors.cursor]
text = '{background}'
cursor = '{cursor}'
[colors.vi_mode_cursor]
text = '{background}'
cursor = '{cursor}'
[colors.selection]
text = 'CellForeground'
background = '{editor_selected}'
[colors.search.matches]
foreground = '{background}'
background = '{base0A}'
[colors.search.focused_match]
foreground = '{background}'
background = '{accent}'
[colors.footer_bar]
foreground = '{foreground}'
background = '{surface}'
[colors.hints.start]
foreground = '{background}'
background = '{warning}'
[colors.hints.end]
foreground = '{background}'
background = '{surface_variant}'
[colors.line_indicator]
foreground = 'None'
background = 'None'
[colors.normal]
black = '{base00}'
red = '{base08}'
green = '{base01}'
yellow = '{base02}'
blue = '{base06}'
magenta = '{base05}'
cyan = '{base0E}'
white = '{base07}'
[colors.bright]
black = '{border_focused}'
red = '{editor_error}'
green = '{editor_success}'
yellow = '{base0A}'
blue = '{editor_link}'
magenta = '{base0D}'
cyan = '{editor_comment}'
white = '{base0F}'
[colors.dim]
black = '{border}'
red = '{base0C}'
green = '{base01}'
yellow = '{editor_string}'
blue = '{base06}'
magenta = '{base05}'
cyan = '{base0E}'
white = '{base07}'

26
extra/templates/ghostty Normal file
View File

@@ -0,0 +1,26 @@
background = {background}
foreground = {foreground}
cursor-color = {cursor}
cursor-text = {foreground}
selection-background = {editor_selected}
selection-foreground = {foreground}
palette = 0={base00}
palette = 1={base08}
palette = 2={base01}
palette = 3={base02}
palette = 4={base06}
palette = 5={base05}
palette = 6={base0E}
palette = 7={base07}
palette = 8={border_focused}
palette = 9={editor_error}
palette = 10={editor_success}
palette = 11={base0A}
palette = 12={editor_link}
palette = 13={base0D}
palette = 14={editor_comment}
palette = 15={base0F}

View File

@@ -0,0 +1,32 @@
cursor {cursor}
cursor_text_color {background}
foreground {foreground}
background {background}
selection_foreground {on_surface}
selection_background {surface}
url_color {accent}
color0 {base00}
color8 {base08}
color1 {base01}
color9 {base09}
color2 {base02}
color10 {base0A}
color3 {base03}
color11 {base0B}
color4 {base04}
color12 {base0C}
color5 {base05}
color13 {base0D}
color6 {base06}
color14 {base0E}
color7 {base07}
color15 {base0F}

93
extra/templates/nvim.lua Normal file
View File

@@ -0,0 +1,93 @@
vim.cmd("highlight clear")
vim.cmd("syntax reset")
vim.g.colors_name = "clrsync"
local palette = {
-- Editor colors
Default = "{editor_main.hex}",
Keyword = "{editor_command.hex}",
Number = "{editor_warning.hex}",
String = "{editor_string.hex}",
CharLiteral = "{editor_string.hex}",
Punctuation = "{editor_main.hex}",
Preprocessor = "{editor_emphasis.hex}",
Identifier = "{editor_main.hex}",
KnownIdentifier = "{editor_link.hex}",
PreprocIdentifier = "{editor_link.hex}",
Comment = "{editor_comment.hex}",
MultiLineComment = "{editor_comment.hex}",
Background = "{editor_background.hex}",
Cursor = "{cursor.hex}",
Selection = "{editor_selected.hex}",
ErrorMarker = "{editor_error.hex}",
Breakpoint = "{editor_error.hex}",
LineNumber = "{editor_line_number.hex}",
CurrentLineFill = "{surface_variant.hex}",
CurrentLineFillInactive = "{surface.hex}",
CurrentLineEdge = "{border_focused.hex}",
-- Semantic colors
Success = "{success.hex}",
Warning = "{warning.hex}",
Error = "{error.hex}",
Info = "{info.hex}",
}
-- Helper function to set highlights in Neovim
local function set_hl(group, opts)
vim.api.nvim_set_hl(0, group, opts)
end
vim.o.winborder = "rounded"
-- Basic editor highlights using the mapped palette
set_hl("Normal", { fg = palette.Default, bg = palette.Background })
set_hl("CursorLine", { bg = palette.CurrentLineFill })
set_hl("Visual", { bg = palette.Selection })
set_hl("LineNr", { fg = palette.LineNumber })
set_hl("CursorLineNr", { fg = palette.Keyword })
-- Syntax highlights
set_hl("Comment", { fg = palette.Comment, italic = true })
set_hl("Constant", { fg = palette.Number })
set_hl("String", { fg = palette.String })
set_hl("Character", { fg = palette.CharLiteral })
set_hl("Identifier", { fg = palette.Identifier })
set_hl("Function", { fg = palette.Keyword })
set_hl("Statement", { fg = palette.Keyword })
set_hl("PreProc", { fg = palette.Preprocessor })
set_hl("Type", { fg = palette.Keyword })
set_hl("Special", { fg = palette.PreprocIdentifier })
set_hl("Underlined", { fg = palette.KnownIdentifier })
set_hl("Error", { fg = palette.ErrorMarker, bg = palette.Background })
set_hl("Todo", { fg = palette.Default, bg = palette.Keyword })
-- Floating windows
set_hl("NormalFloat", { bg = palette.Background })
set_hl("FloatBorder", { fg = palette.CurrentLineEdge, bg = palette.Background })
-- Completion menu
set_hl("Pmenu", { bg = palette.Background })
set_hl("PmenuSel", { bg = palette.Keyword, fg = palette.Background })
-- Git and diagnostic highlights
set_hl("DiffAdd", { fg = palette.Success, bg = palette.Background })
set_hl("DiffChange", { fg = palette.Keyword, bg = palette.Background })
set_hl("DiffDelete", { fg = palette.ErrorMarker, bg = palette.Background })
set_hl("DiagnosticError", { fg = palette.Error })
set_hl("DiagnosticWarn", { fg = palette.Warning })
set_hl("DiagnosticInfo", { fg = palette.Info })
set_hl("DiagnosticHint", { fg = palette.PreprocIdentifier })
-- Treesitter links
set_hl("@comment", { link = "Comment" })
set_hl("@string", { fg = palette.String })
set_hl("@function", { fg = palette.Keyword })
set_hl("@variable", { fg = palette.Identifier })
set_hl("@keyword", { fg = palette.Keyword })
set_hl("@type", { fg = palette.Preprocessor })

6
flake.lock generated
View File

@@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1764950072,
"narHash": "sha256-BmPWzogsG2GsXZtlT+MTcAWeDK5hkbGRZTeZNW42fwA=",
"lastModified": 1765779637,
"narHash": "sha256-KJ2wa/BLSrTqDjbfyNx70ov/HdgNBCBBSQP3BIzKnv4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f61125a668a320878494449750330ca58b78c557",
"rev": "1306659b587dc277866c7b69eb97e5f07864d8c4",
"type": "github"
},
"original": {

View File

@@ -13,6 +13,14 @@
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
baseVersion = nixpkgs.lib.removeSuffix "\n" (builtins.readFile ./VERSION);
semver =
if self ? rev then
"${baseVersion}+git.${builtins.substring 0 7 self.rev}"
else
"${baseVersion}+dev";
in
{
packages = forAllSystems (
@@ -21,7 +29,7 @@
pkgs = nixpkgsFor.${system};
in
rec {
clrsync = pkgs.callPackage ./package.nix { };
clrsync = pkgs.callPackage ./package.nix { inherit semver; };
default = clrsync;
}
);
@@ -59,12 +67,12 @@
system:
let
pkgs = nixpkgsFor.${system};
clrsync = self.packages.${system}.clrsync;
in
{
default = pkgs.mkShell {
inputsFrom = [ self.packages.${system}.clrsync ];
buildInputs = with pkgs; [
inputsFrom = [ clrsync ];
packages = with pkgs; [
cmake
ninja
clang-tools

View File

@@ -5,6 +5,7 @@
git,
pkg-config,
makeWrapper,
wrapGAppsHook3,
wayland-protocols,
glfw,
freetype,
@@ -16,11 +17,16 @@
zlib,
bzip2,
wayland-scanner,
gtk3,
glib,
gsettings-desktop-schemas,
semver,
}:
stdenv.mkDerivation rec {
pname = "clrsync";
version = "unstable-2024-12-15";
version = semver;
src = lib.cleanSourceWith {
src = ./.;
@@ -46,6 +52,7 @@ stdenv.mkDerivation rec {
git
pkg-config
makeWrapper
wrapGAppsHook3
wayland-protocols
];
@@ -65,11 +72,15 @@ stdenv.mkDerivation rec {
libxkbcommon
zlib
bzip2
gtk3
gsettings-desktop-schemas
glib
];
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Release"
"-DUSE_SYSTEM_GLFW=ON"
"-DCLRSYNC_SEMVER=${version}"
];
installPhase = ''
@@ -77,21 +88,17 @@ stdenv.mkDerivation rec {
cmake --install . --prefix $out
wrapProgram $out/bin/clrsync_gui \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs}
wrapProgram $out/bin/clrsync_cli \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs}
runHook postInstall
'';
dontWrapGApps = false;
meta = with lib; {
description = "Color scheme manager with GUI and CLI";
homepage = "https://github.com/obsqrbtz/clrsync";
license = licenses.mit;
platforms = platforms.linux;
mainProgram = "clrsync_gui";
maintainers = [ ];
maintainers = [ "Daniel Dada" ];
};
}

View File

@@ -4,14 +4,15 @@
#include <argparse/argparse.hpp>
#include <core/config/config.hpp>
#include <core/io/toml_file.hpp>
#include <core/palette/palette_file.hpp>
#include <core/palette/palette_manager.hpp>
#include <core/theme/theme_renderer.hpp>
#include <core/theme/theme_template.hpp>
#include <core/utils.hpp>
#include <core/version.hpp>
#include "core/common/error.hpp"
#include "core/common/utils.hpp"
#include "core/common/version.hpp"
#include "core/config/config.hpp"
#include "core/io/toml_file.hpp"
#include "core/palette/palette_file.hpp"
#include "core/palette/palette_manager.hpp"
#include "core/theme/theme_renderer.hpp"
#include "core/theme/theme_template.hpp"
void handle_show_vars()
{
@@ -35,16 +36,17 @@ int handle_apply_theme(const argparse::ArgumentParser &program, const std::strin
{
clrsync::core::theme_renderer<clrsync::core::io::toml_file> renderer;
std::string theme_identifier;
clrsync::core::Result<void> result = clrsync::core::Ok();
if (program.is_used("--theme"))
{
theme_identifier = program.get<std::string>("--theme");
renderer.apply_theme(theme_identifier);
result = renderer.apply_theme(theme_identifier);
}
else if (program.is_used("--path"))
{
theme_identifier = program.get<std::string>("--path");
renderer.apply_theme_from_path(theme_identifier);
result = renderer.apply_theme_from_path(theme_identifier);
}
else
{
@@ -54,17 +56,23 @@ int handle_apply_theme(const argparse::ArgumentParser &program, const std::strin
return 1;
}
theme_identifier = default_theme;
renderer.apply_theme(theme_identifier);
result = renderer.apply_theme(theme_identifier);
}
if (!result)
{
std::cerr << "Failed to apply theme: " << result.error().description() << std::endl;
return 1;
}
std::cout << "Applied theme " << theme_identifier << std::endl;
return 0;
}
void initialize_config(const std::string &config_path)
clrsync::core::Result<void> initialize_config(const std::string &config_path)
{
auto conf = std::make_unique<clrsync::core::io::toml_file>(config_path);
clrsync::core::config::instance().initialize(std::move(conf));
return clrsync::core::config::instance().initialize(std::move(conf));
}
void setup_argument_parser(argparse::ArgumentParser &program)
@@ -103,13 +111,10 @@ int main(int argc, char *argv[])
std::string config_path = program.get<std::string>("--config");
try
auto config_result = initialize_config(config_path);
if (!config_result)
{
initialize_config(config_path);
}
catch (const std::exception &err)
{
std::cerr << "Error loading config: " << err.what() << std::endl;
std::cerr << "Error loading config: " << config_result.error().description() << std::endl;
return 1;
}

View File

@@ -2,8 +2,8 @@ set(CORE_SOURCES
palette/color.cpp
io/toml_file.cpp
config/config.cpp
utils.cpp
version.cpp
common/utils.cpp
common/version.cpp
theme/theme_template.cpp
)

266
src/core/common/error.hpp Normal file
View File

@@ -0,0 +1,266 @@
#ifndef CLRSYNC_CORE_ERROR_HPP
#define CLRSYNC_CORE_ERROR_HPP
#include <optional>
#include <string>
#include <variant>
namespace clrsync::core
{
enum class error_code
{
unknown,
file_not_found,
file_open_failed,
file_write_failed,
file_read_failed,
dir_create_failed,
parse_failed,
invalid_format,
config_missing,
config_invalid,
template_not_found,
template_load_failed,
template_apply_failed,
palette_not_found,
palette_load_failed,
init_failed,
invalid_arg,
resource_missing,
};
inline const char *error_code_string(error_code code)
{
switch (code)
{
case error_code::unknown:
return "Unknown error";
case error_code::file_not_found:
return "File not found";
case error_code::file_open_failed:
return "Failed to open file";
case error_code::file_write_failed:
return "Failed to write file";
case error_code::file_read_failed:
return "Failed to read file";
case error_code::dir_create_failed:
return "Failed to create directory";
case error_code::parse_failed:
return "Parse failed";
case error_code::invalid_format:
return "Invalid format";
case error_code::config_missing:
return "Configuration missing";
case error_code::config_invalid:
return "Configuration invalid";
case error_code::template_not_found:
return "Template not found";
case error_code::template_load_failed:
return "Failed to load template";
case error_code::template_apply_failed:
return "Failed to apply template";
case error_code::palette_not_found:
return "Palette not found";
case error_code::palette_load_failed:
return "Failed to load palette";
case error_code::init_failed:
return "Initialization failed";
case error_code::invalid_arg:
return "Invalid argument";
case error_code::resource_missing:
return "Resource missing";
default:
return "Unknown error code";
}
}
struct Error
{
error_code code;
std::string message;
std::string context;
Error(error_code c) : code(c), message(error_code_string(c))
{
}
Error(error_code c, std::string msg) : code(c), message(std::move(msg))
{
}
Error(error_code c, std::string msg, std::string ctx)
: code(c), message(std::move(msg)), context(std::move(ctx))
{
}
std::string description() const
{
if (context.empty())
return message;
return message + " [" + context + "]";
}
};
template <typename T> class [[nodiscard]] Result
{
private:
std::variant<T, Error> m_data;
public:
Result(T value) : m_data(std::move(value))
{
}
Result(Error error) : m_data(std::move(error))
{
}
bool is_ok() const
{
return std::holds_alternative<T>(m_data);
}
bool is_error() const
{
return std::holds_alternative<Error>(m_data);
}
explicit operator bool() const
{
return is_ok();
}
T &value() &
{
return std::get<T>(m_data);
}
const T &value() const &
{
return std::get<T>(m_data);
}
T &&value() &&
{
return std::get<T>(std::move(m_data));
}
const Error &error() const
{
return std::get<Error>(m_data);
}
T value_or(T default_value) const
{
return is_ok() ? std::get<T>(m_data) : std::move(default_value);
}
std::optional<T> ok() const
{
if (is_ok())
return std::get<T>(m_data);
return std::nullopt;
}
std::optional<Error> err() const
{
if (is_error())
return std::get<Error>(m_data);
return std::nullopt;
}
template <typename F> auto map(F &&func) -> Result<decltype(func(std::declval<T>()))>
{
using U = decltype(func(std::declval<T>()));
if (is_ok())
return Result<U>(func(std::get<T>(m_data)));
return Result<U>(std::get<Error>(m_data));
}
template <typename F> auto and_then(F &&func) -> decltype(func(std::declval<T>()))
{
if (is_ok())
return func(std::get<T>(m_data));
using ResultType = decltype(func(std::declval<T>()));
return ResultType(std::get<Error>(m_data));
}
};
template <> class [[nodiscard]] Result<void>
{
private:
std::optional<Error> m_error;
public:
Result() : m_error(std::nullopt)
{
}
Result(Error error) : m_error(std::move(error))
{
}
bool is_ok() const
{
return !m_error.has_value();
}
bool is_error() const
{
return m_error.has_value();
}
explicit operator bool() const
{
return is_ok();
}
const Error &error() const
{
return *m_error;
}
std::optional<Error> err() const
{
return m_error;
}
};
template <typename T> Result<T> Ok(T value)
{
return Result<T>(std::move(value));
}
inline Result<void> Ok()
{
return Result<void>();
}
template <typename T> Result<T> Err(Error error)
{
return Result<T>(std::move(error));
}
template <typename T> Result<T> Err(error_code code)
{
return Result<T>(Error(code));
}
template <typename T> Result<T> Err(error_code code, std::string message)
{
return Result<T>(Error(code, std::move(message)));
}
template <typename T> Result<T> Err(error_code code, std::string message, std::string context)
{
return Result<T>(Error(code, std::move(message), std::move(context)));
}
} // namespace clrsync::core
#endif // CLRSYNC_CORE_ERROR_HPP

56
src/core/common/utils.cpp Normal file
View File

@@ -0,0 +1,56 @@
#include "utils.hpp"
#include <filesystem>
#include <iostream>
namespace clrsync::core
{
void print_color_keys()
{
for (const auto &key : clrsync::core::COLOR_KEYS)
{
std::cout << key << std::endl;
}
}
std::string get_default_config_path()
{
const char *env_path = std::getenv("CLRSYNC_CONFIG_PATH");
if (env_path && env_path[0] != '\0')
return normalize_path(env_path).string();
std::filesystem::path home = normalize_path("~");
std::filesystem::path config_path = home / ".config" / "clrsync" / "config.toml";
return config_path.string();
}
std::string expand_user(const std::string &path)
{
if (path.empty() || path[0] != '~')
return path;
if (path.length() == 1 || path[1] == '/' || path[1] == '\\')
{
#ifdef _WIN32
const char *home = std::getenv("USERPROFILE");
#else
const char *home = std::getenv("HOME");
#endif
if (!home)
return path;
if (path.length() == 1)
return std::string(home);
return std::string(home) + path.substr(1);
}
return path;
}
std::filesystem::path normalize_path(const std::string &path)
{
std::string expanded = expand_user(path);
std::filesystem::path fs_path(expanded);
return fs_path.lexically_normal();
}
} // namespace clrsync::core

View File

@@ -1,14 +1,16 @@
#ifndef CLRSYNC_CORE_UTILS_HPP
#define CLRSYNC_CORE_UTILS_HPP
#include <filesystem>
#include <string>
#include <core/palette/color_keys.hpp>
#include "core/palette/color_keys.hpp"
namespace clrsync::core
{
void print_color_keys();
std::string get_default_config_path();
std::string expand_user(const std::string &path);
std::filesystem::path normalize_path(const std::string &path);
} // namespace clrsync::core
#endif // CLRSYNC_CORE_UTILS_HPP

View File

@@ -0,0 +1,9 @@
#include "core/common/version.hpp"
namespace clrsync::core
{
const std::string version_string()
{
return GIT_SEMVER;
}
} // namespace clrsync::core

View File

@@ -1,15 +1,12 @@
#ifndef CLRSYNC_CORE_VERSION_HPP
#define CLRSYNC_CORE_VERSION_HPP
#include <cstdint>
#include <string>
namespace clrsync::core
{
constexpr uint8_t VERSION_MAJOR = 0;
constexpr uint8_t VERSION_MINOR = 1;
constexpr uint8_t VERSION_PATCH = 4;
const std::string GIT_SEMVER = "1.0.0+git.g5b0599a";
const std::string version_string();
} // namespace clrsync::core

View File

@@ -1,15 +1,12 @@
#ifndef CLRSYNC_CORE_VERSION_HPP
#define CLRSYNC_CORE_VERSION_HPP
#include <cstdint>
#include <string>
namespace clrsync::core
{
constexpr uint8_t VERSION_MAJOR = @PROJECT_VERSION_MAJOR@;
constexpr uint8_t VERSION_MINOR = @PROJECT_VERSION_MINOR@;
constexpr uint8_t VERSION_PATCH = @PROJECT_VERSION_PATCH@;
const std::string GIT_SEMVER = "@SEMVER@";
const std::string version_string();
} // namespace clrsync::core

View File

@@ -1,14 +1,16 @@
#include "config.hpp"
#include "core/utils.hpp"
#include "core/common/error.hpp"
#include "core/common/utils.hpp"
#include "core/io/toml_file.hpp"
#include <core/palette/color.hpp>
#include "core/palette/color.hpp"
#include <filesystem>
#include <fstream>
#include <stdexcept>
#ifdef _WIN32
#include "windows.h"
#endif
#include <iostream>
namespace clrsync::core
{
@@ -18,24 +20,80 @@ config &config::instance()
return inst;
}
void config::initialize(std::unique_ptr<clrsync::core::io::file> file)
Result<void> config::initialize(std::unique_ptr<clrsync::core::io::file> file)
{
copy_default_configs();
m_file = std::move(file);
if (m_file)
if (!m_file->parse())
throw std::runtime_error{"Could not parse config file"};
if (!m_file)
return Err<void>(error_code::config_missing, "Config file is missing");
auto parse_result = m_file->parse();
if (!parse_result)
return Err<void>(error_code::config_invalid, parse_result.error().message,
parse_result.error().context);
std::filesystem::path config_path = get_user_config_dir() / "config.toml";
std::filesystem::path temp_config_path = get_user_config_dir() / "config-temp.toml";
if (std::filesystem::exists(config_path))
{
std::error_code ec;
auto perms = std::filesystem::status(config_path, ec).permissions();
if (ec || (perms & std::filesystem::perms::owner_write) == std::filesystem::perms::none)
{
m_temp_config_path = temp_config_path.string();
if (std::filesystem::exists(temp_config_path))
{
try
{
auto temp_conf = std::make_unique<clrsync::core::io::toml_file>(temp_config_path.string());
auto temp_parse = temp_conf->parse();
if (temp_parse)
{
m_temp_file = std::move(temp_conf);
}
}
catch (const std::exception &e)
{
std::cerr << "Warning: Failed to load temp config: " << e.what() << std::endl;
}
}
}
}
return Ok();
}
std::filesystem::path config::get_user_config_dir()
{
auto home = expand_user("~");
#ifdef _WIN32
return home + "\\.config\\clrsync";
std::filesystem::path home = normalize_path("~");
return home / ".config" / "clrsync";
}
#else
return home + "/.config/clrsync";
#endif
std::filesystem::path config::get_user_state_dir()
{
std::filesystem::path home = normalize_path("~");
return home / ".local" / "state" / "clrsync";
}
std::filesystem::path config::get_writable_config_path()
{
std::filesystem::path config_path = get_user_config_dir() / "config.toml";
if (std::filesystem::exists(config_path))
{
std::error_code ec;
auto perms = std::filesystem::status(config_path, ec).permissions();
if (ec || (perms & std::filesystem::perms::owner_write) == std::filesystem::perms::none)
{
return get_user_config_dir() / "config-temp.toml";
}
}
return config_path;
}
std::filesystem::path config::get_data_dir()
@@ -62,13 +120,23 @@ void config::copy_file(const std::filesystem::path &src, const std::filesystem::
if (std::filesystem::exists(dst))
return;
if (!std::filesystem::exists(src))
return;
std::ifstream in(src, std::ios::binary);
std::ofstream out(dst, std::ios::binary);
if (!in || !out)
return;
out << in.rdbuf();
}
void config::copy_dir(const std::filesystem::path &src, const std::filesystem::path &dst)
{
if (!std::filesystem::exists(src))
return;
for (auto const &entry : std::filesystem::recursive_directory_iterator(src))
{
auto rel = std::filesystem::relative(entry.path(), src);
@@ -92,6 +160,9 @@ void config::copy_default_configs()
std::filesystem::create_directories(user_dir);
if (system_dir.empty())
return;
{
auto src = system_dir / "config.toml";
auto dst = user_dir / "config.toml";
@@ -120,15 +191,50 @@ void config::copy_default_configs()
}
}
Result<void> config::save_config_value(const std::string &section, const std::string &key, const value_type &value)
{
if (!m_temp_config_path.empty())
{
if (!m_temp_file)
{
m_temp_file = std::make_unique<clrsync::core::io::toml_file>(m_temp_config_path);
(void)m_temp_file->parse();
}
m_temp_file->set_value(section, key, value);
return m_temp_file->save_file();
}
m_file->set_value(section, key, value);
return m_file->save_file();
}
const std::string &config::palettes_path()
{
if (m_palettes_dir.empty() && m_file)
{
if (m_temp_file)
{
auto temp_value = m_temp_file->get_string_value("general", "palettes_path");
if (!temp_value.empty())
{
m_palettes_dir = temp_value;
return m_palettes_dir;
}
}
m_palettes_dir = m_file->get_string_value("general", "palettes_path");
}
return m_palettes_dir;
}
const std::string config::default_theme() const
{
if (m_temp_file)
{
auto temp_value = m_temp_file->get_string_value("general", "default_theme");
if (!temp_value.empty())
return temp_value;
}
if (m_file)
return m_file->get_string_value("general", "default_theme");
return {};
@@ -136,6 +242,12 @@ const std::string config::default_theme() const
const std::string config::font() const
{
if (m_temp_file)
{
auto temp_value = m_temp_file->get_string_value("general", "font");
if (!temp_value.empty())
return temp_value;
}
if (m_file)
return m_file->get_string_value("general", "font");
return {};
@@ -143,55 +255,106 @@ const std::string config::font() const
const uint32_t config::font_size() const
{
if (m_temp_file)
{
auto temp_value = m_temp_file->get_uint_value("general", "font_size");
if (temp_value != 0)
return temp_value;
}
if (m_file)
return m_file->get_uint_value("general", "font_size");
return 14;
}
void config::set_default_theme(const std::string &theme)
Result<void> config::set_default_theme(const std::string &theme)
{
if (m_file)
{
m_file->set_value("general", "default_theme", theme);
m_file->save_file();
}
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
return save_config_value("general", "default_theme", theme);
}
void config::set_palettes_path(const std::string &path)
Result<void> config::set_palettes_path(const std::string &path)
{
if (m_file)
{
m_file->set_value("general", "palettes_path", path);
m_file->save_file();
}
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
return save_config_value("general", "palettes_path", path);
}
void config::set_font(const std::string &font)
Result<void> config::set_font(const std::string &font)
{
if (m_file)
{
m_file->set_value("general", "font", font);
m_file->save_file();
}
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
return save_config_value("general", "font", font);
}
void config::set_font_size(int font_size)
Result<void> config::set_font_size(int font_size)
{
if (m_file)
{
m_file->set_value("general", "font_size", font_size);
m_file->save_file();
}
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
return save_config_value("general", "font_size", static_cast<uint32_t>(font_size));
}
void config::update_template(const std::string &key,
Result<void> config::update_template(const std::string &key,
const clrsync::core::theme_template &theme_template)
{
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
m_themes[key] = theme_template;
m_file->set_value("templates." + key, "input_path", theme_template.template_path());
m_file->set_value("templates." + key, "output_path", theme_template.output_path());
m_file->set_value("templates." + key, "enabled", theme_template.enabled());
m_file->set_value("templates." + key, "reload_cmd", theme_template.reload_command());
m_file->save_file();
auto result1 = save_config_value("templates." + key, "input_path", theme_template.template_path());
if (!result1) return result1;
auto result2 = save_config_value("templates." + key, "output_path", theme_template.output_path());
if (!result2) return result2;
auto result3 = save_config_value("templates." + key, "enabled", theme_template.enabled());
if (!result3) return result3;
return save_config_value("templates." + key, "reload_cmd", theme_template.reload_command());
}
Result<void> config::remove_template(const std::string &key)
{
if (!m_file)
return Err<void>(error_code::config_missing, "Configuration not initialized");
auto it = m_themes.find(key);
if (it == m_themes.end())
return Err<void>(error_code::template_not_found, "Template not found", key);
std::filesystem::path template_file = it->second.template_path();
if (std::filesystem::exists(template_file))
{
try
{
std::filesystem::remove(template_file);
}
catch (const std::exception &e)
{
return Err<void>(error_code::file_write_failed, "Failed to delete template file",
e.what());
}
}
m_themes.erase(it);
if (!m_temp_config_path.empty())
{
if (!m_temp_file)
{
m_temp_file = std::make_unique<clrsync::core::io::toml_file>(m_temp_config_path);
(void)m_temp_file->parse();
}
m_temp_file->remove_section("templates." + key);
return m_temp_file->save_file();
}
m_file->remove_section("templates." + key);
return m_file->save_file();
}
const std::unordered_map<std::string, clrsync::core::theme_template> config::templates()
@@ -214,21 +377,23 @@ const std::unordered_map<std::string, clrsync::core::theme_template> config::tem
theme.set_enabled(false);
}
theme.set_reload_command(std::get<std::string>(current["reload_cmd"]));
theme.load_template();
(void)theme.load_template();
m_themes.insert({theme.name(), theme});
}
}
return m_themes;
}
const clrsync::core::theme_template &config::template_by_name(const std::string &name) const
Result<const clrsync::core::theme_template *> config::template_by_name(
const std::string &name) const
{
auto it = m_themes.find(name);
if (it != m_themes.end())
{
return it->second;
return Ok(&it->second);
}
throw std::runtime_error("Template not found: " + name);
return Err<const clrsync::core::theme_template *>(error_code::template_not_found,
"Template not found", name);
}
} // namespace clrsync::core

View File

@@ -1,8 +1,9 @@
#ifndef CLRSYNC_CORE_CONFIG_HPP
#define CLRSYNC_CORE_CONFIG_HPP
#include <core/io/file.hpp>
#include <core/theme/theme_template.hpp>
#include "core/common/error.hpp"
#include "core/io/file.hpp"
#include "core/theme/theme_template.hpp"
#include <filesystem>
#include <memory>
#include <string>
@@ -14,24 +15,26 @@ class config
public:
static config &instance();
void initialize(std::unique_ptr<clrsync::core::io::file> file);
Result<void> initialize(std::unique_ptr<clrsync::core::io::file> file);
const std::string font() const;
const uint32_t font_size() const;
const std::string &palettes_path();
const std::string default_theme() const;
const std::unordered_map<std::string, clrsync::core::theme_template> templates();
const clrsync::core::theme_template &template_by_name(const std::string &name) const;
Result<const clrsync::core::theme_template *> template_by_name(const std::string &name) const;
std::filesystem::path get_user_config_dir();
std::filesystem::path get_user_state_dir();
std::filesystem::path get_writable_config_path();
Result<void> set_default_theme(const std::string &theme);
Result<void> set_palettes_path(const std::string &path);
Result<void> set_font(const std::string &font);
Result<void> set_font_size(int font_size);
void set_default_theme(const std::string &theme);
void set_palettes_path(const std::string &path);
void set_font(const std::string &font);
void set_font_size(int font_size);
void update_template(const std::string &key,
Result<void> update_template(const std::string &key,
const clrsync::core::theme_template &theme_template);
Result<void> remove_template(const std::string &key);
static std::filesystem::path get_data_dir();
private:
@@ -41,9 +44,12 @@ class config
std::string m_palettes_dir{};
std::unique_ptr<io::file> m_file;
std::unique_ptr<io::file> m_temp_file;
std::string m_temp_config_path;
std::unordered_map<std::string, theme_template> m_themes{};
static void copy_file(const std::filesystem::path& src, const std::filesystem::path& dst);
static void copy_dir(const std::filesystem::path& src, const std::filesystem::path& dst);
Result<void> save_config_value(const std::string &section, const std::string &key, const value_type &value);
static void copy_file(const std::filesystem::path &src, const std::filesystem::path &dst);
static void copy_dir(const std::filesystem::path &src, const std::filesystem::path &dst);
void copy_default_configs();
};
} // namespace clrsync::core

View File

@@ -1,5 +1,6 @@
#ifndef CLRSYNC_CORE_IO_FILE_HPP
#define CLRSYNC_CORE_IO_FILE_HPP
#include "core/common/error.hpp"
#include <cstdint>
#include <map>
#include <string>
@@ -14,7 +15,11 @@ class file
public:
file() = default;
file(std::string path) {};
virtual bool parse() { return false; };
virtual ~file() = default;
virtual Result<void> parse()
{
return Ok();
};
virtual const std::string get_string_value(const std::string &section,
const std::string &key) const
{
@@ -39,7 +44,11 @@ class file
}
virtual void insert_or_update_value(const std::string &section, const std::string &key,
const value_type &value) {};
virtual void save_file() {};
virtual void remove_section(const std::string &section) {};
virtual Result<void> save_file()
{
return Ok();
};
};
} // namespace clrsync::core::io
#endif

View File

@@ -1,5 +1,5 @@
#include "toml_file.hpp"
#include "core/utils.hpp"
#include "core/io/toml_file.hpp"
#include "core/common/utils.hpp"
#include <filesystem>
#include <fstream>
#include <vector>
@@ -8,15 +8,16 @@ namespace clrsync::core::io
{
toml_file::toml_file(std::string path)
{
m_path = expand_user(path);
m_path = normalize_path(path).string();
}
bool toml_file::parse()
Result<void> toml_file::parse()
{
if (!std::filesystem::exists(m_path))
return false;
return Err<void>(error_code::file_not_found, "File does not exist", m_path);
m_file = toml::parse_file(m_path);
return true;
return Ok();
}
const std::string toml_file::get_string_value(const std::string &section,
@@ -63,7 +64,7 @@ std::map<std::string, value_type> toml_file::get_table(const std::string &sectio
else if (auto d = val.value<double>())
result[std::string(p.first.str())] = static_cast<uint32_t>(*d);
else
result[std::string(p.first.str())] = {}; // fallback for unsupported types
result[std::string(p.first.str())] = {};
}
return result;
@@ -91,11 +92,45 @@ void toml_file::insert_or_update_value(const std::string &section, const std::st
std::visit([&](auto &&v) { tbl->insert_or_assign(key, v); }, value);
}
void toml_file::save_file()
void toml_file::remove_section(const std::string &section)
{
toml::table *tbl = m_file.as_table();
auto parts = split(section, '.');
if (parts.empty())
return;
for (size_t i = 0; i < parts.size() - 1; ++i)
{
auto *sub = (*tbl)[parts[i]].as_table();
if (!sub)
return;
tbl = sub;
}
tbl->erase(parts.back());
}
Result<void> toml_file::save_file()
{
try
{
std::filesystem::create_directories(std::filesystem::path(m_path).parent_path());
}
catch (const std::exception &e)
{
return Err<void>(error_code::dir_create_failed, e.what(), m_path);
}
std::ofstream stream(m_path, std::ios::binary);
if (!stream)
return Err<void>(error_code::file_write_failed, "Failed to open file for writing", m_path);
stream << m_file;
if (!stream)
return Err<void>(error_code::file_write_failed, "Failed to write to file", m_path);
return Ok();
}
std::vector<std::string> toml_file::split(const std::string &s, char delim) const

View File

@@ -1,6 +1,7 @@
#ifndef CLRSYNC_CORE_IO_TOML_FILE_HPP
#define CLRSYNC_CORE_IO_TOML_FILE_HPP
#include <core/io/file.hpp>
#include "core/common/error.hpp"
#include "core/io/file.hpp"
#include <string>
#include <toml/toml.hpp>
@@ -10,7 +11,7 @@ class toml_file : public file
{
public:
explicit toml_file(std::string path);
bool parse() override;
Result<void> parse() override;
const std::string get_string_value(const std::string &section,
const std::string &key) const override;
uint32_t get_uint_value(const std::string &section, const std::string &key) const override;
@@ -18,7 +19,8 @@ class toml_file : public file
std::map<std::string, value_type> get_table(const std::string &section_path) const override;
void insert_or_update_value(const std::string &section, const std::string &key,
const value_type &value) override;
void save_file() override;
void remove_section(const std::string &section) override;
Result<void> save_file() override;
private:
toml::parse_result m_file{};

View File

@@ -3,7 +3,6 @@
#include <cstdio>
#include <format>
#include <stdexcept>
#include <unordered_map>
namespace clrsync::core
{
@@ -112,14 +111,17 @@ void color::from_hex_string(const std::string &str)
if (str.empty() || str[0] != '#')
throw std::invalid_argument("Invalid hex color format");
if (str.size() == 7) {
if (str.size() == 7)
{
uint32_t rgb = static_cast<uint32_t>(std::stoul(str.substr(1), nullptr, 16));
m_hex = (rgb << 8) | 0xFF;
}
else if (str.size() == 9) {
else if (str.size() == 9)
{
m_hex = static_cast<uint32_t>(std::stoul(str.substr(1), nullptr, 16));
}
else {
else
{
throw std::invalid_argument("Invalid hex color format");
}
}
@@ -138,30 +140,38 @@ const std::string color::to_hex_string_with_alpha() const
return std::string(buffer);
}
std::string color::format(const std::string& field) const
std::string color::format(const std::string &field) const
{
auto rgb = to_rgb();
auto rgba = to_rgba();
auto hslv = to_hsl();
auto hslav = to_hsla();
if (field == "hex") return to_hex_string();
if (field == "hex_stripped") {
if (field == "hex")
return to_hex_string();
if (field == "hex_stripped")
{
auto s = to_hex_string();
return s.substr(1);
}
if (field == "hexa") return to_hex_string_with_alpha();
if (field == "hexa_stripped") {
if (field == "hexa")
return to_hex_string_with_alpha();
if (field == "hexa_stripped")
{
auto s = to_hex_string_with_alpha();
return s.substr(1);
}
if (field == "r") return std::to_string(rgb.r);
if (field == "g") return std::to_string(rgb.g);
if (field == "b") return std::to_string(rgb.b);
if (field == "r")
return std::to_string(rgb.r);
if (field == "g")
return std::to_string(rgb.g);
if (field == "b")
return std::to_string(rgb.b);
if (field == "a") {
if (field == "a")
{
float af = rgba.a / 255.0f;
return std::format("{:.2f}", af);
}
@@ -170,9 +180,7 @@ std::string color::format(const std::string& field) const
return std::format("rgb({},{},{})", rgb.r, rgb.g, rgb.b);
if (field == "rgba")
return std::format("rgba({},{},{},{:.2f})",
rgba.r, rgba.g, rgba.b,
rgba.a / 255.0f);
return std::format("rgba({},{},{},{:.2f})", rgba.r, rgba.g, rgba.b, rgba.a / 255.0f);
if (field == "h")
return std::format("{:.0f}", hslv.h);
@@ -186,12 +194,10 @@ std::string color::format(const std::string& field) const
return std::format("{:.2f}", hslav.a);
if (field == "hsl")
return std::format("hsl({:.0f},{:.2f},{:.2f})",
hslv.h, hslv.s, hslv.l);
return std::format("hsl({:.0f},{:.2f},{:.2f})", hslv.h, hslv.s, hslv.l);
if (field == "hsla")
return std::format("hsla({:.0f},{:.2f},{:.2f},{:.2f})",
hslav.h, hslav.s, hslav.l, hslav.a);
return std::format("hsla({:.0f},{:.2f},{:.2f},{:.2f})", hslav.h, hslav.s, hslav.l, hslav.a);
throw std::runtime_error("Unknown color format: " + field);
}

View File

@@ -60,7 +60,7 @@ class color
const std::string to_hex_string_with_alpha() const;
std::string format(const std::string& field) const;
std::string format(const std::string &field) const;
void set(uint32_t hex);

View File

@@ -1,11 +1,14 @@
#ifndef CLRSYNC_CORE_PALETTE_COLOR_KEYS_HPP
#define CLRSYNC_CORE_PALETTE_COLOR_KEYS_HPP
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <string>
#include <unordered_map>
namespace clrsync::core
{
constexpr const char* COLOR_KEYS[] = {
constexpr const char *COLOR_KEYS[] = {
// General UI
"background",
"on_background",
@@ -72,5 +75,67 @@ constexpr const char* COLOR_KEYS[] = {
};
constexpr size_t NUM_COLOR_KEYS = std::size(COLOR_KEYS);
inline const std::unordered_map<std::string, uint32_t> DEFAULT_COLORS = {
{"background", 0x111111ff},
{"on_background", 0xd4d4d4ff},
{"surface", 0x111111ff},
{"on_surface", 0xd4d4d4ff},
{"surface_variant", 0x191919ff},
{"on_surface_variant", 0xd4d4d4ff},
{"border_focused", 0x2e2e2eff},
{"border", 0x242424ff},
{"foreground", 0xd2d2d2ff},
{"cursor", 0xd2d2d2ff},
{"accent", 0x9a8652ff},
{"success", 0x668a51ff},
{"info", 0x3a898cff},
{"warning", 0xb47837ff},
{"error", 0xaa4e4aff},
{"on_success", 0xd2d2d2ff},
{"on_info", 0xd2d2d2ff},
{"on_warning", 0xd2d2d2ff},
{"on_error", 0xd2d2d2ff},
{"editor_background", 0x111111ff},
{"editor_command", 0x3a898cff},
{"editor_comment", 0x849899ff},
{"editor_disabled", 0x849899ff},
{"editor_emphasis", 0xa9dc86ff},
{"editor_error", 0xaa4e4aff},
{"editor_inactive", 0x849899ff},
{"editor_line_number", 0x849899ff},
{"editor_link", 0xb0779eff},
{"editor_main", 0xd2d2d2ff},
{"editor_selected", 0x242424ff},
{"editor_selection_inactive", 0x1d1c1cff},
{"editor_string", 0x9a8652ff},
{"editor_success", 0x668a51ff},
{"editor_warning", 0xb47837ff},
{"base00", 0x111111ff},
{"base01", 0x668a51ff},
{"base02", 0x9a8652ff},
{"base03", 0xb47837ff},
{"base04", 0x9a5552ff},
{"base05", 0xaa477bff},
{"base06", 0x3a898cff},
{"base07", 0xb5b5b5ff},
{"base08", 0xaa4e4aff},
{"base09", 0xa9dc86ff},
{"base0A", 0xb6ab82ff},
{"base0B", 0xc5916bff},
{"base0C", 0xac7676ff},
{"base0D", 0xb0779eff},
{"base0E", 0x849899ff},
{"base0F", 0xd2d2d2ff},
};
} // namespace clrsync::core
#endif

View File

@@ -4,7 +4,8 @@
#include <string>
#include <unordered_map>
#include <core/palette/color.hpp>
#include "core/palette/color.hpp"
#include "core/palette/color_keys.hpp"
namespace clrsync::core
{
@@ -37,9 +38,16 @@ class palette
{
return it->second;
}
static color default_color{};
auto default_it = DEFAULT_COLORS.find(key);
if (default_it != DEFAULT_COLORS.end())
{
static color default_color;
default_color.set(default_it->second);
return default_color;
}
static color empty_color{};
return empty_color;
}
const std::unordered_map<std::string, color> &colors() const
{

View File

@@ -5,9 +5,9 @@
#include <cstdint>
#include <string>
#include <core/io/file.hpp>
#include <core/palette/color_keys.hpp>
#include <core/palette/palette.hpp>
#include "core/io/file.hpp"
#include "core/palette/color_keys.hpp"
#include "core/palette/palette.hpp"
#include <memory>
@@ -26,14 +26,26 @@ template <typename FileType> class palette_file
if (!m_file->parse())
return false;
m_palette.set_name(m_file->get_string_value("general", "name"));
for (const auto &color_key : COLOR_KEYS)
{
auto it = DEFAULT_COLORS.find(color_key);
if (it != DEFAULT_COLORS.end())
{
m_palette.set_color(color_key, core::color(it->second));
}
}
for (const auto &color_key : COLOR_KEYS)
{
auto color_str = m_file->get_string_value("colors", color_key);
core::color color{0x000000FF};
if (!color_str.empty())
{
core::color color;
color.from_hex_string(color_str);
m_palette.set_color(color_key, color);
}
}
return true;
}
core::palette palette() const
@@ -52,7 +64,7 @@ template <typename FileType> class palette_file
}
void save()
{
m_file->save_file();
(void)m_file->save_file();
}
private:

View File

@@ -1,14 +1,13 @@
#ifndef CLRSYNC_CORE_PALETTE_PALETTE_MANAGER_HPP
#define CLRSYNC_CORE_PALETTE_PALETTE_MANAGER_HPP
#include "core/utils.hpp"
#include <iostream>
#include "core/common/utils.hpp"
#include <string>
#include <unordered_map>
#include <core/config/config.hpp>
#include <core/palette/palette.hpp>
#include <core/palette/palette_file.hpp>
#include "core/config/config.hpp"
#include "core/palette/palette.hpp"
#include "core/palette/palette_file.hpp"
#include <filesystem>
namespace clrsync::core
@@ -19,12 +18,9 @@ template <typename FileType> class palette_manager
palette_manager() = default;
void load_palettes_from_directory(const std::string &directory_path)
{
auto directory_path_expanded = expand_user(directory_path);
std::filesystem::path directory_path_expanded = normalize_path(directory_path);
if (!std::filesystem::exists(directory_path_expanded))
{
std::cerr << "Palettes directory does not exist\n" ;
return;
}
for (const auto &entry : std::filesystem::directory_iterator(directory_path_expanded))
{
if (entry.is_regular_file())
@@ -37,8 +33,9 @@ template <typename FileType> class palette_manager
}
void save_palette_to_file(const palette &pal, const std::string &directory_path) const
{
std::string file_path = directory_path + "/" + pal.name() + ".toml";
palette_file<FileType> pal_file(file_path);
std::filesystem::path dir_path = normalize_path(directory_path);
std::filesystem::path file_path = dir_path / (pal.name() + ".toml");
palette_file<FileType> pal_file(file_path.string());
pal_file.save_palette(pal);
}

View File

@@ -1,17 +1,15 @@
#ifndef CLRSYNC_CORE_THEME_TEMPLATE_MANAGER_HPP
#define CLRSYNC_CORE_THEME_TEMPLATE_MANAGER_HPP
#include <core/config/config.hpp>
#include <core/theme/theme_template.hpp>
#include "core/config/config.hpp"
#include "core/theme/theme_template.hpp"
#include <string>
#include <unordered_map>
namespace clrsync::core
{
template <typename FileType>
class template_manager
template <typename FileType> class template_manager
{
public:
template_manager() = default;

View File

@@ -1,8 +1,10 @@
#ifndef CLRSYNC_CORE_THEME_THEME_RENDERER_HPP
#define CLRSYNC_CORE_THEME_THEME_RENDERER_HPP
#include <core/config/config.hpp>
#include <core/palette/palette_manager.hpp>
#include <core/theme/template_manager.hpp>
#include "core/common/error.hpp"
#include "core/config/config.hpp"
#include "core/palette/palette_manager.hpp"
#include "core/theme/template_manager.hpp"
#include <iostream>
#include <string>
namespace clrsync::core
@@ -18,39 +20,54 @@ template <typename FileType> class theme_renderer
m_template_manager = template_manager<FileType>();
}
void apply_theme(const std::string &theme_name)
Result<void> apply_theme(const std::string &theme_name)
{
auto palette = m_pal_manager.get_palette(theme_name);
if (!palette)
throw std::runtime_error("Palette not found: " + theme_name);
apply_palette_to_all_templates(*palette);
return Err<void>(error_code::palette_not_found, "Palette not found", theme_name);
return apply_palette_to_all_templates(*palette);
}
void apply_theme_from_path(const std::string &path)
Result<void> apply_theme_from_path(const std::string &path)
{
auto palette = m_pal_manager.load_palette_from_file(path);
apply_palette_to_all_templates(palette);
return apply_palette_to_all_templates(palette);
}
private:
palette_manager<FileType> m_pal_manager;
template_manager<FileType> m_template_manager;
void apply_palette_to_all_templates(const palette &pal)
Result<void> apply_palette_to_all_templates(const palette &pal)
{
for (auto &t_pair : m_template_manager.templates())
{
auto &tmpl = t_pair.second;
if (!tmpl.enabled())
continue;
tmpl.load_template();
auto load_result = tmpl.load_template();
if (!load_result)
return load_result;
tmpl.apply_palette(pal);
tmpl.save_output();
auto save_result = tmpl.save_output();
if (!save_result)
return save_result;
if (!tmpl.reload_command().empty())
{
std::system(tmpl.reload_command().c_str());
int result = std::system(tmpl.reload_command().c_str());
if (result != 0)
{
std::cerr << "Warning: Command " << tmpl.reload_command()
<< " failed with code " << result << "\n";
}
}
}
return Ok();
}
};
} // namespace clrsync::core

View File

@@ -1,5 +1,5 @@
#include "theme_template.hpp"
#include "core/utils.hpp"
#include "core/common/utils.hpp"
#include <filesystem>
#include <fstream>
#include <iostream>
@@ -8,8 +8,8 @@ namespace clrsync::core
{
theme_template::theme_template(const std::string &name, const std::string &template_path,
const std::string &out_path)
: m_name(name), m_template_path(expand_user(template_path)),
m_output_path(expand_user(out_path))
: m_name(name), m_template_path(normalize_path(template_path).string()),
m_output_path(normalize_path(out_path).string())
{
}
@@ -30,7 +30,7 @@ const std::string &theme_template::template_path() const
void theme_template::set_template_path(const std::string &path)
{
m_template_path = expand_user(path);
m_template_path = normalize_path(path).string();
}
const std::string &theme_template::output_path() const
@@ -40,28 +40,33 @@ const std::string &theme_template::output_path() const
void theme_template::set_output_path(const std::string &path)
{
m_output_path = expand_user(path);
m_output_path = normalize_path(path).string();
}
void theme_template::load_template()
Result<void> theme_template::load_template()
{
if (!std::filesystem::exists(m_template_path))
{
std::cerr << "Template file '" << m_template_path << "' is missing\n";
return;
return Err<void>(error_code::template_not_found, "Template file is missing",
m_template_path);
}
std::ifstream input(m_template_path, std::ios::binary);
if (!input)
throw std::runtime_error("Failed to open template file: " + m_template_path);
{
return Err<void>(error_code::template_load_failed, "Failed to open template file",
m_template_path);
}
m_template_data.assign(std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>());
return Ok();
}
void theme_template::apply_palette(const core::palette &palette)
{
m_processed_data = m_template_data;
for (const auto& [key, color] : palette.colors())
for (const auto &[key, color] : palette.colors())
{
// simple replacement: {foreground}
replace_all(m_processed_data, "{" + key + "}", color.format("hex"));
@@ -87,14 +92,32 @@ void theme_template::apply_palette(const core::palette &palette)
}
}
void theme_template::save_output() const
Result<void> theme_template::save_output() const
{
try
{
std::filesystem::create_directories(std::filesystem::path(m_output_path).parent_path());
}
catch (const std::exception &e)
{
return Err<void>(error_code::dir_create_failed, e.what(), m_output_path);
}
std::ofstream output(m_output_path, std::ios::binary);
if (!output)
throw std::runtime_error("Failed to write output file: " + m_output_path);
{
return Err<void>(error_code::file_write_failed, "Failed to open output file for writing",
m_output_path);
}
output << m_processed_data;
if (!output)
{
return Err<void>(error_code::file_write_failed, "Failed to write to output file",
m_output_path);
}
return Ok();
}
const std::string &theme_template::raw_template() const

View File

@@ -1,7 +1,8 @@
#ifndef clrsync_CORE_IO_THEME_TEMPLATE_HPP
#define clrsync_CORE_IO_THEME_TEMPLATE_HPP
#include <core/palette/palette.hpp>
#include "core/common/error.hpp"
#include "core/palette/palette.hpp"
#include <string>
namespace clrsync::core
@@ -26,11 +27,11 @@ class theme_template
void set_output_path(const std::string &path);
void load_template();
Result<void> load_template();
void apply_palette(const core::palette &palette);
void save_output() const;
Result<void> save_output() const;
const std::string &raw_template() const;

View File

@@ -1,41 +0,0 @@
#include "utils.hpp"
#include <iostream>
namespace clrsync::core
{
void print_color_keys()
{
for (const auto &key : clrsync::core::COLOR_KEYS)
{
std::cout << key << std::endl;
}
}
std::string get_default_config_path()
{
auto home = expand_user("~");
#ifdef _WIN32
return home + "\\.config\\clrsync\\config.toml";
#else
return home + "/.config/clrsync/config.toml";
#endif
}
std::string expand_user(const std::string &path)
{
if (!path.empty() && path[0] == '~')
{
#ifdef _WIN32
const char *home = std::getenv("USERPROFILE");
#else
const char *home = std::getenv("HOME");
#endif
if (!home)
return path;
return std::string(home) + path.substr(1);
}
return path;
}
} // namespace clrsync::core

View File

@@ -1,10 +0,0 @@
#include "version.hpp"
namespace clrsync::core
{
const std::string version_string()
{
return "v" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." +
std::to_string(VERSION_PATCH);
}
} // namespace clrsync::core

View File

@@ -1,18 +1,51 @@
set(GUI_SOURCES
main.cpp
color_scheme_editor.cpp
template_editor.cpp
palette_controller.cpp
template_controller.cpp
imgui_helpers.cpp
imgui_helpers.hpp
about_window.cpp
settings_window.cpp
font_loader.cpp
views/color_scheme_editor.cpp
views/color_table_renderer.cpp
views/preview_renderer.cpp
controllers/theme_applier.cpp
views/template_editor.cpp
controllers/palette_controller.cpp
controllers/template_controller.cpp
views/about_window.cpp
views/settings_window.cpp
widgets/colors.cpp
widgets/dialogs.cpp
widgets/palette_selector.cpp
widgets/input_dialog.cpp
widgets/action_buttons.cpp
widgets/styled_checkbox.cpp
widgets/autocomplete.cpp
widgets/form_field.cpp
widgets/error_message.cpp
widgets/settings_buttons.cpp
widgets/section_header.cpp
widgets/link_button.cpp
widgets/centered_text.cpp
widgets/validation_message.cpp
widgets/template_controls.cpp
layout/main_layout.cpp
platform/windows/font_loader_windows.cpp
platform/linux/font_loader_linux.cpp
platform/macos/font_loader_macos.cpp
platform/linux/file_browser_linux.cpp
platform/windows/file_browser_windows.cpp
${CMAKE_SOURCE_DIR}/lib/color_text_edit/TextEditor.cpp
backend/glfw_opengl.cpp
ui_manager.cpp
)
add_executable(clrsync_gui ${GUI_SOURCES})
if(MACOS)
list(APPEND GUI_SOURCES
platform/macos/file_browser_macos.mm
)
endif()
if(WIN32)
add_executable(clrsync_gui WIN32 ${GUI_SOURCES})
else()
add_executable(clrsync_gui ${GUI_SOURCES})
endif()
target_include_directories(clrsync_gui PRIVATE
${CMAKE_SOURCE_DIR}/src
@@ -25,6 +58,22 @@ if(WIN32)
glfw
imgui
OpenGL::GL
shell32
ole32
uuid
comdlg32
shlwapi
)
if (MSVC)
target_link_options(clrsync_gui PRIVATE /ENTRY:mainCRTStartup)
endif()
elseif(APPLE)
target_link_libraries(clrsync_gui PRIVATE
clrsync_core
glfw
imgui
OpenGL::GL
"-framework Cocoa"
)
else()
target_link_libraries(clrsync_gui PRIVATE
@@ -37,5 +86,9 @@ else()
Xi
Fontconfig::Fontconfig
OpenGL::GL
${GTK3_LIBRARIES}
)
target_include_directories(clrsync_gui PRIVATE ${GTK3_INCLUDE_DIRS})
target_compile_options(clrsync_gui PRIVATE ${GTK3_CFLAGS_OTHER})
endif()

View File

@@ -1,89 +0,0 @@
#include "about_window.hpp"
#include "core/version.hpp"
#include "imgui.h"
about_window::about_window()
{
}
void about_window::render()
{
if (!m_visible)
return;
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
if (ImGui::Begin("About clrsync", &m_visible, ImGuiWindowFlags_NoResize))
{
const float window_width = ImGui::GetContentRegionAvail().x;
ImGui::PushFont(ImGui::GetFont());
const char* title = "clrsync";
const float title_size = ImGui::CalcTextSize(title).x;
ImGui::SetCursorPosX((window_width - title_size) * 0.5f);
ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f), "%s", title);
ImGui::PopFont();
std::string version = "Version " + clrsync::core::version_string();
const float version_size = ImGui::CalcTextSize(version.c_str()).x;
ImGui::SetCursorPosX((window_width - version_size) * 0.5f);
ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "%s", version.c_str());
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::TextWrapped(
"A color scheme management tool."
);
ImGui::Spacing();
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::Text("Links:");
if (ImGui::Button("GitHub Repository", ImVec2(200, 0)))
{
#ifdef _WIN32
system("start https://github.com/obsqrbtz/clrsync");
#elif __APPLE__
system("open https://github.com/obsqrbtz/clrsync");
#else
system("xdg-open https://github.com/obsqrbtz/clrsync");
#endif
}
ImGui::SameLine();
ImGui::Spacing();
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1.0f), "MIT License");
ImGui::TextWrapped(
"Copyright (c) 2025 Daniel Dada\n\n"
"Permission is hereby granted, free of charge, to any person obtaining a copy "
"of this software and associated documentation files (the \"Software\"), to deal "
"in the Software without restriction, including without limitation the rights "
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell "
"copies of the Software, and to permit persons to whom the Software is "
"furnished to do so, subject to the following conditions:\n\n"
"The above copyright notice and this permission notice shall be included in all "
"copies or substantial portions of the Software."
);
ImGui::Spacing();
ImGui::Spacing();
const float button_width = 120.0f;
ImGui::SetCursorPosX((window_width - button_width) * 0.5f);
if (ImGui::Button("Close", ImVec2(button_width, 0)))
{
m_visible = false;
}
}
ImGui::End();
}

View File

@@ -1,17 +0,0 @@
#ifndef CLRSYNC_GUI_ABOUT_WINDOW_HPP
#define CLRSYNC_GUI_ABOUT_WINDOW_HPP
class about_window
{
public:
about_window();
void render();
void show() { m_visible = true; }
void hide() { m_visible = false; }
bool is_visible() const { return m_visible; }
private:
bool m_visible{false};
};
#endif // CLRSYNC_GUI_ABOUT_WINDOW_HPP

View File

@@ -0,0 +1,37 @@
#ifndef CLRSYNC_BACKEND_HPP
#define CLRSYNC_BACKEND_HPP
#include <string>
namespace clrsync::gui::backend{
struct window_config{
std::string title = "clrsync";
int width = 1280;
int height = 720;
bool decorated = true;
bool transparent_framebuffer = true;
float clear_color[4] = {0.1f, 0.1f, 0.1f, 0.0f};
};
class backend_interface{
public:
virtual ~backend_interface() = default;
virtual bool initialize(const window_config& config) = 0;
virtual void shutdown() = 0;
virtual bool should_close() const = 0;
virtual void begin_frame() = 0;
virtual void end_frame() = 0;
virtual void* get_native_window() const = 0;
virtual void* get_graphics_context() const = 0;
virtual bool init_imgui_backend() = 0;
virtual void shutdown_imgui_backend() = 0;
virtual void imgui_new_frame() = 0;
virtual void imgui_render_draw_data(void* draw_data) = 0;
};
}
#endif // CLRSYNC_BACKEND_HPP

View File

@@ -0,0 +1,158 @@
#include "gui/backend/glfw_opengl.hpp"
#include <iostream>
#include <string>
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
namespace clrsync::gui::backend
{
glfw_opengl_backend::glfw_opengl_backend() = default;
glfw_opengl_backend::~glfw_opengl_backend()
{
glfw_opengl_backend::shutdown();
}
bool glfw_opengl_backend::initialize(const window_config &config)
{
glfwSetErrorCallback([](int error, const char* description) {
std::cerr << "GLFW Error " << error << ": " << description << std::endl;
});
if (!glfwInit())
{
std::cerr << "Failed to initialize GLFW" << std::endl;
return false;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
#ifdef __APPLE__
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
#else
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
#endif
glfwWindowHint(GLFW_RESIZABLE,GLFW_TRUE);
glfwWindowHint(GLFW_DECORATED, config.decorated ? GLFW_TRUE : GLFW_FALSE);
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, config.transparent_framebuffer ? GLFW_TRUE : GLFW_FALSE);
m_window = glfwCreateWindow(config.width, config.height, config.title.c_str(), nullptr, nullptr);
if (!m_window)
{
std::cerr << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return false;
}
glfwMakeContextCurrent(m_window);
glfwSwapInterval(1);
return true;
}
void glfw_opengl_backend::shutdown()
{
if (m_window)
{
glfwDestroyWindow(m_window);
m_window = nullptr;
}
glfwTerminate();
}
bool glfw_opengl_backend::should_close() const
{
return m_window && glfwWindowShouldClose(m_window);
}
void glfw_opengl_backend::begin_frame()
{
glfwPollEvents();
if (m_window)
{
int display_w, display_h;
glfwGetFramebufferSize(m_window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
}
void glfw_opengl_backend::end_frame()
{
if (m_window)
{
glfwSwapBuffers(m_window);
}
}
void *glfw_opengl_backend::get_native_window() const
{
return static_cast<void *>(m_window);
}
void *glfw_opengl_backend::get_graphics_context() const
{
return static_cast<void *>(m_window);
}
std::string glfw_opengl_backend::get_glfw_version() const
{
return glfwGetVersionString();
}
std::string glfw_opengl_backend::get_glfw_platform() const
{
switch (glfwGetPlatform()) {
case GLFW_PLATFORM_WAYLAND: return "Wayland";
case GLFW_PLATFORM_X11: return "X11";
case GLFW_PLATFORM_COCOA: return "Cocoa";
case GLFW_PLATFORM_WIN32: return "Win32";
default: return "Unknown";
}
}
bool glfw_opengl_backend::init_imgui_backend()
{
if (!m_window)
return false;
if (!ImGui_ImplGlfw_InitForOpenGL(m_window, true))
return false;
#ifdef __APPLE__
const char* glsl_version = "#version 150";
#else
const char* glsl_version = "#version 120";
#endif
if (!ImGui_ImplOpenGL3_Init(glsl_version))
{
ImGui_ImplGlfw_Shutdown();
return false;
}
return true;
}
void glfw_opengl_backend::shutdown_imgui_backend()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
}
void glfw_opengl_backend::imgui_new_frame()
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
}
void glfw_opengl_backend::imgui_render_draw_data(void* draw_data)
{
ImGui_ImplOpenGL3_RenderDrawData(static_cast<ImDrawData*>(draw_data));
}
} // namespace clrsync::gui::backend

View File

@@ -0,0 +1,39 @@
#ifndef CLRSYNC_GLFW_OPENGL_HPP
#define CLRSYNC_GLFW_OPENGL_HPP
#define GL_SILENCE_DEPRECATION
#include <GLFW/glfw3.h>
#include "gui/backend/backend.hpp"
namespace clrsync::gui::backend{
class glfw_opengl_backend : public backend_interface{
public:
glfw_opengl_backend();
~glfw_opengl_backend();
bool initialize(const window_config& config) override;
void shutdown() override;
bool should_close() const override;
void begin_frame() override;
void end_frame() override;
void* get_native_window() const override;
void* get_graphics_context() const override;
std::string get_glfw_version() const;
std::string get_glfw_platform() const;
bool init_imgui_backend() override;
void shutdown_imgui_backend() override;
void imgui_new_frame() override;
void imgui_render_draw_data(void* draw_data) override;
private:
GLFWwindow* m_window = nullptr;
};
}
#endif // CLRSYNC_GLFW_OPENGL_HPP

View File

@@ -1,555 +0,0 @@
#include "color_scheme_editor.hpp"
#include "template_editor.hpp"
#include "color_text_edit/TextEditor.h"
#include "imgui.h"
#include <iostream>
#include <ranges>
color_scheme_editor::color_scheme_editor()
{
m_editor.SetLanguageDefinition(TextEditor::LanguageDefinition::CPlusPlus());
m_editor.SetText(R"(#include <iostream>
#include <string>
#include <vector>
#include <filesystem>
#include <cstdlib>
namespace fs = std::filesystem;
// Expands ~ to the user's home directory
std::string expand_user(const std::string &path)
{
if (path.empty()) return "";
std::string result;
if (path[0] == '~')
{
#ifdef _WIN32
const char* home = std::getenv("USERPROFILE");
#else
const char* home = std::getenv("HOME");
#endif
result = home ? std::string(home) : "~";
result += path.substr(1);
}
else
{
result = path;
}
return result;
}
// Lists all files in a directory
std::vector<std::string> list_files(const std::string &dir_path)
{
std::vector<std::string> files;
try
{
for (const auto &entry : fs::directory_iterator(dir_path))
{
if (entry.is_regular_file())
files.push_back(entry.path().string());
}
}
catch (const std::exception &e)
{
std::cerr << "Error: " << e.what() << std::endl;
}
return files;
}
int main()
{
std::string path = expand_user("~/Documents");
std::cout << "Listing files in: " << path << std::endl;
auto files = list_files(path);
for (const auto &f : files)
std::cout << " " << f << std::endl;
return 0;
})");
m_editor.SetShowWhitespaces(false);
const auto &palettes = m_controller.palettes();
const auto &current = m_controller.current_palette();
if (!current.colors().empty())
{
apply_palette_to_imgui();
apply_palette_to_editor();
}
else
{
std::cout << "WARNING: No palette loaded, skipping theme application\n";
}
}
void color_scheme_editor::notify_palette_changed()
{
if (m_template_editor)
{
m_template_editor->apply_current_palette(m_controller.current_palette());
}
}
void color_scheme_editor::render_controls_and_colors()
{
ImGui::Begin("Color Schemes");
render_controls();
ImGui::Separator();
ImGui::BeginChild("ColorTableContent", ImVec2(0, 0), false);
render_color_table();
ImGui::EndChild();
ImGui::End();
}
void color_scheme_editor::render_preview()
{
ImGui::Begin("Color Preview");
render_preview_content();
ImGui::End();
}
void color_scheme_editor::render_controls()
{
const auto &current = m_controller.current_palette();
const auto &palettes = m_controller.palettes();
const float avail_width = ImGui::GetContentRegionAvail().x;
ImGui::Text("Color Scheme:");
ImGui::SameLine();
ImGui::SetNextItemWidth(std::min(200.0f, avail_width * 0.3f));
if (ImGui::BeginCombo("##scheme", current.name().c_str()))
{
for (const auto &name : palettes | std::views::keys)
{
const bool selected = current.name() == name;
if (ImGui::Selectable(name.c_str(), selected))
{
m_controller.select_palette(name);
apply_palette_to_imgui();
apply_palette_to_editor();
notify_palette_changed();
}
if (selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::SameLine();
static char new_palette_name_buf[128] = "";
if (ImGui::Button("New"))
{
new_palette_name_buf[0] = 0;
ImGui::OpenPopup("New Palette");
}
if (ImGui::BeginPopupModal("New Palette", nullptr, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("New palette name:");
ImGui::InputText("##new_palette_input", new_palette_name_buf,
IM_ARRAYSIZE(new_palette_name_buf));
ImGui::Separator();
if (ImGui::Button("Create", ImVec2(120, 0)))
{
if (strlen(new_palette_name_buf) > 0)
{
m_controller.create_palette(new_palette_name_buf);
apply_palette_to_imgui();
apply_palette_to_editor();
notify_palette_changed();
m_controller.select_palette(new_palette_name_buf);
new_palette_name_buf[0] = 0;
}
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Cancel", ImVec2(120, 0)))
{
new_palette_name_buf[0] = 0;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
ImGui::SameLine();
if (ImGui::Button("Save"))
{
m_controller.save_current_palette();
}
ImGui::SameLine();
if (ImGui::Button("Delete"))
{
m_controller.delete_current_palette();
}
ImGui::SameLine();
if (ImGui::Button("Apply"))
{
m_controller.apply_current_theme();
}
}
void color_scheme_editor::render_color_table()
{
const auto &current = m_controller.current_palette();
if (current.colors().empty())
{
ImGui::Text("No palette loaded");
return;
}
ImGui::Text("Color Variables");
ImGui::Separator();
auto render_color_row = [&](const std::string &name) {
const auto &colors = current.colors();
auto it = colors.find(name);
if (it == colors.end())
return;
const clrsync::core::color &col = it->second;
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::TextUnformatted(name.c_str());
ImGui::TableSetColumnIndex(1);
{
std::string hex_str = col.to_hex_string();
char buf[9];
strncpy(buf, hex_str.c_str(), sizeof(buf));
buf[8] = 0;
ImGui::SetNextItemWidth(-FLT_MIN);
if (ImGui::InputText(("##hex_" + name).c_str(), buf, sizeof(buf),
ImGuiInputTextFlags_CharsUppercase))
{
try
{
clrsync::core::color new_color;
new_color.from_hex_string(buf);
m_controller.set_color(name, new_color);
apply_palette_to_imgui();
apply_palette_to_editor();
notify_palette_changed();
}
catch (...)
{
}
}
}
ImGui::TableSetColumnIndex(2);
ImGui::PushID(name.c_str());
float c[4] = {((col.hex() >> 24) & 0xFF) / 255.0f, ((col.hex() >> 16) & 0xFF) / 255.0f,
((col.hex() >> 8) & 0xFF) / 255.0f, (col.hex() & 0xFF) / 255.0f};
ImGui::SetNextItemWidth(-FLT_MIN);
if (ImGui::ColorEdit4(("##color_" + name).c_str(), c,
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel |
ImGuiColorEditFlags_AlphaBar))
{
uint32_t r = (uint32_t)(c[0] * 255.0f);
uint32_t g = (uint32_t)(c[1] * 255.0f);
uint32_t b = (uint32_t)(c[2] * 255.0f);
uint32_t a = (uint32_t)(c[3] * 255.0f);
uint32_t hex = (r << 24) | (g << 16) | (b << 8) | a;
m_controller.set_color(name, clrsync::core::color(hex));
apply_palette_to_imgui();
apply_palette_to_editor();
notify_palette_changed();
}
ImGui::PopID();
};
auto draw_table = [&](const char *title, const std::vector<const char *> &keys) {
ImGui::TextUnformatted(title);
if (ImGui::BeginTable(title, 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
{
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 160.0f);
ImGui::TableSetupColumn("HEX", ImGuiTableColumnFlags_WidthFixed, 90.0f);
ImGui::TableSetupColumn("Preview", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableHeadersRow();
for (auto *k : keys)
render_color_row(k);
ImGui::EndTable();
}
ImGui::Spacing();
};
draw_table("General UI", {"background", "on_background", "surface", "on_surface",
"surface_variant", "on_surface_variant", "foreground",
"cursor", "accent"});
draw_table("Borders", {"border_focused", "border"});
draw_table("Semantic Colors", {"success", "info", "warning", "error",
"on_success", "on_info", "on_warning", "on_error"});
draw_table("Editor", {"editor_background", "editor_command", "editor_comment",
"editor_disabled", "editor_emphasis", "editor_error",
"editor_inactive", "editor_line_number", "editor_link",
"editor_main", "editor_selected", "editor_selection_inactive",
"editor_string", "editor_success", "editor_warning"});
draw_table("Terminal (Base16)", {"base00", "base01", "base02", "base03",
"base04", "base05", "base06", "base07",
"base08", "base09", "base0A", "base0B",
"base0C", "base0D", "base0E", "base0F"});
}
void color_scheme_editor::render_preview_content()
{
const auto &current = m_controller.current_palette();
if (current.colors().empty())
{
ImGui::TextColored(ImVec4(1.0f, 0.3f, 0.3f, 1.0f), "Current palette is empty");
return;
}
auto get_color = [&](const std::string &key) -> ImVec4 {
auto it = current.colors().find(key);
if (it != current.colors().end())
{
const auto &col = it->second;
const uint32_t hex = col.hex();
return {((hex >> 24) & 0xFF) / 255.0f, ((hex >> 16) & 0xFF) / 255.0f,
((hex >> 8) & 0xFF) / 255.0f, ((hex) & 0xFF) / 255.0f};
}
return {1, 1, 1, 1};
};
const ImVec4 editor_bg = get_color("editor_background");
const ImVec4 fg = get_color("foreground");
const ImVec4 accent = get_color("accent");
const ImVec4 border = get_color("border");
const ImVec4 error = get_color("error");
const ImVec4 warning = get_color("warning");
const ImVec4 success = get_color("success");
const ImVec4 info = get_color("info");
const float avail_height = ImGui::GetContentRegionAvail().y;
const float code_preview_height = std::max(250.0f, avail_height * 0.55f);
ImGui::Text("Code Editor:");
m_editor.Render("##CodeEditor", ImVec2(0, code_preview_height), true);
ImGui::Spacing();
ImGui::Text("Terminal Preview:");
ImGui::PushStyleColor(ImGuiCol_ChildBg, editor_bg);
ImGui::BeginChild("TerminalPreview", ImVec2(0, 0), true);
ImGui::PushStyleColor(ImGuiCol_Border, border);
struct term_line
{
const char *text{};
ImVec4 col;
};
term_line term_lines[] = {
{"$ ls -la", fg},
{"drwxr-xr-x 5 user group 4096 Dec 2 10:30 .", accent},
{"Build successful", success},
{"Error: file not found", error},
{"Warning: low disk space", warning},
{"Info: update available", info},
};
for (auto &[text, col] : term_lines)
{
ImGui::TextColored(col, "%s", text);
}
ImGui::PopStyleColor(2);
ImGui::EndChild();
}
void color_scheme_editor::apply_palette_to_editor()
{
const auto &current = m_controller.current_palette();
if (current.colors().empty())
return;
auto get_color_u32 = [&](const std::string &key, const std::string &fallback = "") -> uint32_t {
auto it = current.colors().find(key);
if (it == current.colors().end() && !fallback.empty())
{
it = current.colors().find(fallback);
}
if (it != current.colors().end())
{
const auto &col = it->second;
const uint32_t hex = col.hex();
// Convert from RRGGBBAA to AABBGGRR (ImGui format)
const uint32_t r = (hex >> 24) & 0xFF;
const uint32_t g = (hex >> 16) & 0xFF;
const uint32_t b = (hex >> 8) & 0xFF;
const uint32_t a = hex & 0xFF;
return (a << 24) | (b << 16) | (g << 8) | r;
}
return 0xFFFFFFFF;
};
auto palette = m_editor.GetPalette();
palette[int(TextEditor::PaletteIndex::Default)] = get_color_u32("editor_main");
palette[int(TextEditor::PaletteIndex::Keyword)] = get_color_u32("editor_command");
palette[int(TextEditor::PaletteIndex::Number)] = get_color_u32("editor_warning");
palette[int(TextEditor::PaletteIndex::String)] = get_color_u32("editor_string");
palette[int(TextEditor::PaletteIndex::CharLiteral)] = get_color_u32("editor_string");
palette[int(TextEditor::PaletteIndex::Punctuation)] = get_color_u32("editor_main");
palette[int(TextEditor::PaletteIndex::Preprocessor)] = get_color_u32("editor_emphasis");
palette[int(TextEditor::PaletteIndex::Identifier)] = get_color_u32("editor_main");
palette[int(TextEditor::PaletteIndex::KnownIdentifier)] = get_color_u32("editor_link");
palette[int(TextEditor::PaletteIndex::PreprocIdentifier)] = get_color_u32("editor_link");
palette[int(TextEditor::PaletteIndex::Comment)] = get_color_u32("editor_comment");
palette[int(TextEditor::PaletteIndex::MultiLineComment)] = get_color_u32("editor_comment");
palette[int(TextEditor::PaletteIndex::Background)] = get_color_u32("editor_background");
palette[int(TextEditor::PaletteIndex::Cursor)] = get_color_u32("cursor");
palette[int(TextEditor::PaletteIndex::Selection)] = get_color_u32("editor_selected");
palette[int(TextEditor::PaletteIndex::ErrorMarker)] = get_color_u32("editor_error");
palette[int(TextEditor::PaletteIndex::Breakpoint)] = get_color_u32("editor_error");
palette[int(TextEditor::PaletteIndex::LineNumber)] = get_color_u32("editor_line_number");
palette[int(TextEditor::PaletteIndex::CurrentLineFill)] = get_color_u32("surface_variant");
palette[int(TextEditor::PaletteIndex::CurrentLineFillInactive)] = get_color_u32("surface");
palette[int(TextEditor::PaletteIndex::CurrentLineEdge)] = get_color_u32("border_focused");
m_editor.SetPalette(palette);
}
void color_scheme_editor::apply_palette_to_imgui() const
{
const auto &current = m_controller.current_palette();
if (current.colors().empty())
return;
auto getColor = [&](const std::string &key, const std::string &fallback = "") -> ImVec4 {
auto it = current.colors().find(key);
if (it == current.colors().end() && !fallback.empty())
{
it = current.colors().find(fallback);
}
if (it != current.colors().end())
{
const uint32_t hex = it->second.hex();
return {((hex >> 24) & 0xFF) / 255.0f, ((hex >> 16) & 0xFF) / 255.0f,
((hex >> 8) & 0xFF) / 255.0f, ((hex) & 0xFF) / 255.0f};
}
std::cout << "WARNING: Color key '" << key << "' not found!\n";
return {1, 1, 1, 1};
};
ImGuiStyle &style = ImGui::GetStyle();
const ImVec4 bg = getColor("background");
const ImVec4 surface = getColor("surface");
const ImVec4 surfaceVariant = getColor("surface_variant");
const ImVec4 fg = getColor("foreground");
const ImVec4 fgInactive = getColor("editor_inactive");
const ImVec4 accent = getColor("accent");
const ImVec4 border = getColor("border");
style.Colors[ImGuiCol_WindowBg] = bg;
style.Colors[ImGuiCol_ChildBg] = surface;
style.Colors[ImGuiCol_PopupBg] = surface;
style.Colors[ImGuiCol_Border] = border;
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0, 0, 0, 0);
style.Colors[ImGuiCol_Text] = fg;
style.Colors[ImGuiCol_TextDisabled] = fgInactive;
style.Colors[ImGuiCol_Header] = surfaceVariant;
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(accent.x, accent.y, accent.z, 0.8f);
style.Colors[ImGuiCol_HeaderActive] = accent;
style.Colors[ImGuiCol_Button] = surfaceVariant;
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(accent.x, accent.y, accent.z, 0.6f);
style.Colors[ImGuiCol_ButtonActive] = accent;
style.Colors[ImGuiCol_FrameBg] = surfaceVariant;
style.Colors[ImGuiCol_FrameBgHovered] =
ImVec4(surfaceVariant.x * 1.1f, surfaceVariant.y * 1.1f, surfaceVariant.z * 1.1f, 1.0f);
style.Colors[ImGuiCol_FrameBgActive] =
ImVec4(surfaceVariant.x * 1.2f, surfaceVariant.y * 1.2f, surfaceVariant.z * 1.2f, 1.0f);
style.Colors[ImGuiCol_TitleBg] = surface;
style.Colors[ImGuiCol_TitleBgActive] = surfaceVariant;
style.Colors[ImGuiCol_TitleBgCollapsed] = surface;
style.Colors[ImGuiCol_ScrollbarBg] = surface;
style.Colors[ImGuiCol_ScrollbarGrab] = surfaceVariant;
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(accent.x, accent.y, accent.z, 0.6f);
style.Colors[ImGuiCol_ScrollbarGrabActive] = accent;
style.Colors[ImGuiCol_SliderGrab] = accent;
style.Colors[ImGuiCol_SliderGrabActive] =
ImVec4(accent.x * 1.2f, accent.y * 1.2f, accent.z * 1.2f, 1.0f);
style.Colors[ImGuiCol_CheckMark] = accent;
style.Colors[ImGuiCol_ResizeGrip] = surfaceVariant;
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(accent.x, accent.y, accent.z, 0.6f);
style.Colors[ImGuiCol_ResizeGripActive] = accent;
style.Colors[ImGuiCol_Tab] = surface;
style.Colors[ImGuiCol_TabHovered] = ImVec4(accent.x, accent.y, accent.z, 0.8f);
style.Colors[ImGuiCol_TabActive] = surfaceVariant;
style.Colors[ImGuiCol_TabUnfocused] = surface;
style.Colors[ImGuiCol_TabUnfocusedActive] = surfaceVariant;
style.Colors[ImGuiCol_TabSelectedOverline] = accent;
style.Colors[ImGuiCol_TableHeaderBg] = surfaceVariant;
style.Colors[ImGuiCol_TableBorderStrong] = border;
style.Colors[ImGuiCol_TableBorderLight] =
ImVec4(border.x * 0.7f, border.y * 0.7f, border.z * 0.7f, border.w);
style.Colors[ImGuiCol_TableRowBg] = ImVec4(0, 0, 0, 0);
style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(fg.x, fg.y, fg.z, 0.06f);
style.Colors[ImGuiCol_Separator] = border;
style.Colors[ImGuiCol_SeparatorHovered] = accent;
style.Colors[ImGuiCol_SeparatorActive] = accent;
style.Colors[ImGuiCol_MenuBarBg] = surface;
style.Colors[ImGuiCol_DockingPreview] = ImVec4(accent.x, accent.y, accent.z, 0.7f);
style.Colors[ImGuiCol_DockingEmptyBg] = bg;
}

View File

@@ -1,33 +0,0 @@
#ifndef CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP
#define CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP
#include "color_text_edit/TextEditor.h"
#include "palette_controller.hpp"
class template_editor;
class color_scheme_editor
{
public:
color_scheme_editor();
void render_controls_and_colors();
void render_preview();
void set_template_editor(template_editor* editor) { m_template_editor = editor; }
const palette_controller& controller() const { return m_controller; }
private:
void render_controls();
void render_color_table();
void render_preview_content();
void apply_palette_to_editor();
void apply_palette_to_imgui() const;
void notify_palette_changed();
palette_controller m_controller;
TextEditor m_editor;
template_editor* m_template_editor{nullptr};
};
#endif // CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP

View File

@@ -1,4 +1,4 @@
#include "palette_controller.hpp"
#include "gui/controllers/palette_controller.hpp"
#include "core/config/config.hpp"
#include "core/theme/theme_renderer.hpp"
@@ -11,25 +11,35 @@ palette_controller::palette_controller()
if (m_palettes.empty())
return;
try {
m_current_palette = m_palettes[clrsync::core::config::instance().default_theme()];
} catch (...) {
auto default_theme = clrsync::core::config::instance().default_theme();
auto it = m_palettes.find(default_theme);
if (it != m_palettes.end())
{
m_current_palette = it->second;
}
else
{
m_current_palette = m_palettes.begin()->second;
}
}
void palette_controller::select_palette(const std::string& name)
void palette_controller::select_palette(const std::string &name)
{
auto it = m_palettes.find(name);
if (it != m_palettes.end()) {
if (it != m_palettes.end())
{
m_current_palette = it->second;
}
}
void palette_controller::create_palette(const std::string& name)
void palette_controller::create_palette(const std::string &name)
{
clrsync::core::palette new_palette = m_palette_manager.load_palette_from_file(clrsync::core::config::get_data_dir().string() + "/palettes/cursed.toml");
new_palette.set_name(name);
clrsync::core::palette new_palette(name);
for (const auto &[key, hex_value] : clrsync::core::DEFAULT_COLORS)
{
new_palette.set_color(key, clrsync::core::color(hex_value));
}
auto dir = clrsync::core::config::instance().palettes_path();
m_palette_manager.save_palette_to_file(new_palette, dir);
@@ -54,10 +64,10 @@ void palette_controller::delete_current_palette()
void palette_controller::apply_current_theme() const
{
clrsync::core::theme_renderer<clrsync::core::io::toml_file> theme_renderer;
theme_renderer.apply_theme(m_current_palette.name());
(void)theme_renderer.apply_theme(m_current_palette.name());
}
void palette_controller::set_color(const std::string& key, const clrsync::core::color& color)
void palette_controller::set_color(const std::string &key, const clrsync::core::color &color)
{
m_current_palette.set_color(key, color);
}

View File

@@ -6,21 +6,28 @@
#include <string>
#include <unordered_map>
class palette_controller {
public:
class palette_controller
{
public:
palette_controller();
const clrsync::core::palette& current_palette() const { return m_current_palette; }
const std::unordered_map<std::string, clrsync::core::palette>& palettes() const { return m_palettes; }
const clrsync::core::palette &current_palette() const
{
return m_current_palette;
}
const std::unordered_map<std::string, clrsync::core::palette> &palettes() const
{
return m_palettes;
}
void select_palette(const std::string& name);
void create_palette(const std::string& name);
void select_palette(const std::string &name);
void create_palette(const std::string &name);
void save_current_palette();
void delete_current_palette();
void apply_current_theme() const;
void set_color(const std::string& key, const clrsync::core::color& color);
void set_color(const std::string &key, const clrsync::core::color &color);
private:
private:
void reload_palettes();
clrsync::core::palette_manager<clrsync::core::io::toml_file> m_palette_manager;

View File

@@ -0,0 +1,64 @@
#include "gui/controllers/template_controller.hpp"
#include "core/config/config.hpp"
template_controller::template_controller()
{
m_templates = m_template_manager.templates();
}
void template_controller::set_template_enabled(const std::string &key, bool enabled)
{
auto it = m_templates.find(key);
if (it != m_templates.end())
{
it->second.set_enabled(enabled);
(void)clrsync::core::config::instance().update_template(key, it->second);
}
}
void template_controller::set_template_input_path(const std::string &key, const std::string &path)
{
auto it = m_templates.find(key);
if (it != m_templates.end())
{
it->second.set_template_path(path);
(void)clrsync::core::config::instance().update_template(key, it->second);
}
}
void template_controller::set_template_output_path(const std::string &key, const std::string &path)
{
auto it = m_templates.find(key);
if (it != m_templates.end())
{
it->second.set_output_path(path);
(void)clrsync::core::config::instance().update_template(key, it->second);
}
}
void template_controller::set_template_reload_command(const std::string &key,
const std::string &cmd)
{
auto it = m_templates.find(key);
if (it != m_templates.end())
{
it->second.set_reload_command(cmd);
(void)clrsync::core::config::instance().update_template(key, it->second);
}
}
bool template_controller::remove_template(const std::string &key)
{
auto result = clrsync::core::config::instance().remove_template(key);
if (result)
{
m_templates.erase(key);
return true;
}
return false;
}
void template_controller::refresh()
{
m_templates = m_template_manager.templates();
}

View File

@@ -1,22 +1,29 @@
#ifndef CLRSYNC_GUI_TEMPLATE_CONTROLLER_HPP
#define CLRSYNC_GUI_TEMPLATE_CONTROLLER_HPP
#include "core/theme/theme_template.hpp"
#include "core/theme/template_manager.hpp"
#include "core/io/toml_file.hpp"
#include "core/theme/template_manager.hpp"
#include "core/theme/theme_template.hpp"
#include <string>
#include <unordered_map>
class template_controller {
public:
class template_controller
{
public:
template_controller();
[[nodiscard]] const std::unordered_map<std::string, clrsync::core::theme_template>& templates() const { return m_templates; }
void set_template_enabled(const std::string& key, bool enabled);
void set_template_output_path(const std::string& key, const std::string& path);
void set_template_reload_command(const std::string& key, const std::string& cmd);
[[nodiscard]] const std::unordered_map<std::string, clrsync::core::theme_template> &templates()
const
{
return m_templates;
}
void set_template_enabled(const std::string &key, bool enabled);
void set_template_input_path(const std::string &key, const std::string &path);
void set_template_output_path(const std::string &key, const std::string &path);
void set_template_reload_command(const std::string &key, const std::string &cmd);
bool remove_template(const std::string &key);
void refresh();
private:
private:
clrsync::core::template_manager<clrsync::core::io::toml_file> m_template_manager;
std::unordered_map<std::string, clrsync::core::theme_template> m_templates;
};

View File

@@ -0,0 +1,162 @@
#include "gui/controllers/theme_applier.hpp"
#include "imgui.h"
namespace theme_applier
{
static uint32_t get_color_u32(const clrsync::core::palette &current, const std::string &key)
{
const auto &col = current.get_color(key);
const uint32_t hex = col.hex();
// Convert from RRGGBBAA to AABBGGRR (ImGui format)
const uint32_t r = (hex >> 24) & 0xFF;
const uint32_t g = (hex >> 16) & 0xFF;
const uint32_t b = (hex >> 8) & 0xFF;
const uint32_t a = hex & 0xFF;
return (a << 24) | (b << 16) | (g << 8) | r;
}
void apply_to_editor(TextEditor &editor, const clrsync::core::palette &current)
{
auto palette = editor.GetPalette();
palette[int(TextEditor::PaletteIndex::Default)] = get_color_u32(current, "editor_main");
palette[int(TextEditor::PaletteIndex::Keyword)] = get_color_u32(current, "editor_command");
palette[int(TextEditor::PaletteIndex::Number)] = get_color_u32(current, "editor_warning");
palette[int(TextEditor::PaletteIndex::String)] = get_color_u32(current, "editor_string");
palette[int(TextEditor::PaletteIndex::CharLiteral)] = get_color_u32(current, "editor_string");
palette[int(TextEditor::PaletteIndex::Punctuation)] = get_color_u32(current, "editor_main");
palette[int(TextEditor::PaletteIndex::Preprocessor)] =
get_color_u32(current, "editor_emphasis");
palette[int(TextEditor::PaletteIndex::Identifier)] = get_color_u32(current, "editor_main");
palette[int(TextEditor::PaletteIndex::KnownIdentifier)] = get_color_u32(current, "editor_link");
palette[int(TextEditor::PaletteIndex::PreprocIdentifier)] =
get_color_u32(current, "editor_link");
palette[int(TextEditor::PaletteIndex::Comment)] = get_color_u32(current, "editor_comment");
palette[int(TextEditor::PaletteIndex::MultiLineComment)] =
get_color_u32(current, "editor_comment");
palette[int(TextEditor::PaletteIndex::Background)] =
get_color_u32(current, "editor_background");
palette[int(TextEditor::PaletteIndex::Cursor)] = get_color_u32(current, "cursor");
palette[int(TextEditor::PaletteIndex::Selection)] = get_color_u32(current, "editor_selected");
palette[int(TextEditor::PaletteIndex::ErrorMarker)] = get_color_u32(current, "editor_error");
palette[int(TextEditor::PaletteIndex::Breakpoint)] = get_color_u32(current, "editor_error");
palette[int(TextEditor::PaletteIndex::LineNumber)] =
get_color_u32(current, "editor_line_number");
palette[int(TextEditor::PaletteIndex::CurrentLineFill)] =
get_color_u32(current, "surface_variant");
palette[int(TextEditor::PaletteIndex::CurrentLineFillInactive)] =
get_color_u32(current, "surface");
palette[int(TextEditor::PaletteIndex::CurrentLineEdge)] =
get_color_u32(current, "border_focused");
editor.SetPalette(palette);
}
void apply_to_imgui(const clrsync::core::palette &current)
{
auto getColor = [&](const std::string &key) -> ImVec4 {
const auto &col = current.get_color(key);
const uint32_t hex = col.hex();
return {((hex >> 24) & 0xFF) / 255.0f, ((hex >> 16) & 0xFF) / 255.0f,
((hex >> 8) & 0xFF) / 255.0f, ((hex) & 0xFF) / 255.0f};
};
ImGuiStyle &style = ImGui::GetStyle();
const ImVec4 bg = getColor("background");
const ImVec4 onBg = getColor("on_background");
const ImVec4 surface = getColor("surface");
const ImVec4 onSurface = getColor("on_surface");
const ImVec4 surfaceVariant = getColor("surface_variant");
const ImVec4 onSurfaceVariant = getColor("on_surface_variant");
const ImVec4 fg = getColor("foreground");
const ImVec4 fgInactive = getColor("editor_inactive");
const ImVec4 accent = getColor("accent");
const ImVec4 border = getColor("border");
const ImVec4 error = getColor("error");
const ImVec4 onError = getColor("on_error");
const ImVec4 success = getColor("success");
const ImVec4 onSuccess = getColor("on_success");
const ImVec4 warning = getColor("warning");
const ImVec4 onWarning = getColor("on_warning");
const ImVec4 info = getColor("info");
const ImVec4 onInfo = getColor("on_info");
style.Colors[ImGuiCol_WindowBg] = bg;
style.Colors[ImGuiCol_ChildBg] = surface;
style.Colors[ImGuiCol_PopupBg] = surface;
style.Colors[ImGuiCol_Border] = border;
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0, 0, 0, 0);
style.Colors[ImGuiCol_Text] = onSurface;
style.Colors[ImGuiCol_TextDisabled] = onSurfaceVariant;
style.Colors[ImGuiCol_TextSelectedBg] = accent;
style.Colors[ImGuiCol_Header] = surfaceVariant;
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(accent.x, accent.y, accent.z, 0.8f);
style.Colors[ImGuiCol_HeaderActive] = accent;
style.Colors[ImGuiCol_Button] = surfaceVariant;
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(accent.x, accent.y, accent.z, 0.6f);
style.Colors[ImGuiCol_ButtonActive] = accent;
style.Colors[ImGuiCol_FrameBg] = surfaceVariant;
style.Colors[ImGuiCol_FrameBgHovered] =
ImVec4(surfaceVariant.x * 1.1f, surfaceVariant.y * 1.1f, surfaceVariant.z * 1.1f, 1.0f);
style.Colors[ImGuiCol_FrameBgActive] =
ImVec4(surfaceVariant.x * 1.2f, surfaceVariant.y * 1.2f, surfaceVariant.z * 1.2f, 1.0f);
style.Colors[ImGuiCol_TitleBg] = surface;
style.Colors[ImGuiCol_TitleBgActive] = surfaceVariant;
style.Colors[ImGuiCol_TitleBgCollapsed] = surface;
style.Colors[ImGuiCol_ScrollbarBg] = surface;
style.Colors[ImGuiCol_ScrollbarGrab] = surfaceVariant;
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(accent.x, accent.y, accent.z, 0.6f);
style.Colors[ImGuiCol_ScrollbarGrabActive] = accent;
style.Colors[ImGuiCol_SliderGrab] = accent;
style.Colors[ImGuiCol_SliderGrabActive] =
ImVec4(accent.x * 1.2f, accent.y * 1.2f, accent.z * 1.2f, 1.0f);
style.Colors[ImGuiCol_CheckMark] = accent;
style.Colors[ImGuiCol_ResizeGrip] = surfaceVariant;
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(accent.x, accent.y, accent.z, 0.6f);
style.Colors[ImGuiCol_ResizeGripActive] = accent;
style.Colors[ImGuiCol_Tab] = surface;
style.Colors[ImGuiCol_TabHovered] = ImVec4(accent.x, accent.y, accent.z, 0.8f);
style.Colors[ImGuiCol_TabActive] = surfaceVariant;
style.Colors[ImGuiCol_TabUnfocused] = surface;
style.Colors[ImGuiCol_TabUnfocusedActive] = surfaceVariant;
style.Colors[ImGuiCol_TabSelectedOverline] = accent;
style.Colors[ImGuiCol_TableHeaderBg] = surfaceVariant;
style.Colors[ImGuiCol_TableBorderStrong] = border;
style.Colors[ImGuiCol_TableBorderLight] =
ImVec4(border.x * 0.7f, border.y * 0.7f, border.z * 0.7f, border.w);
style.Colors[ImGuiCol_TableRowBg] = ImVec4(0, 0, 0, 0);
style.Colors[ImGuiCol_TableRowBgAlt] =
ImVec4(onSurfaceVariant.x, onSurfaceVariant.y, onSurfaceVariant.z, 0.06f);
style.Colors[ImGuiCol_Separator] = border;
style.Colors[ImGuiCol_SeparatorHovered] = accent;
style.Colors[ImGuiCol_SeparatorActive] = accent;
style.Colors[ImGuiCol_MenuBarBg] = surface;
style.Colors[ImGuiCol_DockingPreview] = ImVec4(accent.x, accent.y, accent.z, 0.7f);
style.Colors[ImGuiCol_DockingEmptyBg] = bg;
}
} // namespace theme_applier

View File

@@ -0,0 +1,13 @@
#ifndef CLRSYNC_GUI_THEME_APPLIER_HPP
#define CLRSYNC_GUI_THEME_APPLIER_HPP
#include "color_text_edit/TextEditor.h"
#include "core/palette/palette.hpp"
namespace theme_applier
{
void apply_to_imgui(const clrsync::core::palette &pal);
void apply_to_editor(TextEditor &editor, const clrsync::core::palette &pal);
} // namespace theme_applier
#endif // CLRSYNC_GUI_THEME_APPLIER_HPP

View File

@@ -1,228 +0,0 @@
#include "font_loader.hpp"
#include "core/config/config.hpp"
#include "imgui_internal.h"
#include <imgui.h>
#include <algorithm>
#if defined(_WIN32)
#include <algorithm>
#include <windows.h>
#include <winreg.h>
static std::string search_registry_for_font(HKEY root_key, const char* subkey, const std::string& font_name_lower, const char* default_font_dir)
{
HKEY hKey;
LONG result = RegOpenKeyExA(root_key, subkey, 0, KEY_READ, &hKey);
if (result != ERROR_SUCCESS)
return {};
char value_name[512];
BYTE value_data[512];
DWORD value_name_size, value_data_size, type;
DWORD index = 0;
std::string found_path;
while (true)
{
value_name_size = sizeof(value_name);
value_data_size = sizeof(value_data);
result = RegEnumValueA(hKey, index++, value_name, &value_name_size, nullptr, &type, value_data, &value_data_size);
if (result != ERROR_SUCCESS)
break;
if (type != REG_SZ)
continue;
std::string reg_font_name = value_name;
std::transform(reg_font_name.begin(), reg_font_name.end(), reg_font_name.begin(), ::tolower);
if (reg_font_name.find(font_name_lower) != std::string::npos)
{
std::string font_file = reinterpret_cast<char*>(value_data);
// If path is not absolute, prepend default font directory
if (font_file.find(":\\") == std::string::npos)
{
found_path = std::string(default_font_dir) + "\\" + font_file;
}
else
{
found_path = font_file;
}
break;
}
}
RegCloseKey(hKey);
return found_path;
}
std::string font_loader::find_font_windows(const char* font_name)
{
std::string font_name_lower = font_name;
std::transform(font_name_lower.begin(), font_name_lower.end(), font_name_lower.begin(), ::tolower);
char windows_dir[MAX_PATH];
GetWindowsDirectoryA(windows_dir, MAX_PATH);
std::string system_fonts_dir = std::string(windows_dir) + "\\Fonts";
// First, try system-wide fonts (HKEY_LOCAL_MACHINE)
std::string path = search_registry_for_font(
HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
font_name_lower,
system_fonts_dir.c_str()
);
if (!path.empty())
return path;
// If not found, try per-user fonts (HKEY_CURRENT_USER)
char local_appdata[MAX_PATH];
if (GetEnvironmentVariableA("LOCALAPPDATA", local_appdata, MAX_PATH) > 0)
{
std::string user_fonts_dir = std::string(local_appdata) + "\\Microsoft\\Windows\\Fonts";
path = search_registry_for_font(
HKEY_CURRENT_USER,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
font_name_lower,
user_fonts_dir.c_str()
);
}
return path;
}
#endif
#if defined(__APPLE__)
#include <CoreText/CoreText.h>
std::vector<unsigned char> font_loader::load_font_macos(const char* font_name)
{
std::vector<unsigned char> out;
CFStringRef cf_name = CFStringCreateWithCString(nullptr, font_name, kCFStringEncodingUTF8);
if (!cf_name)
return out;
CTFontDescriptorRef desc = CTFontDescriptorCreateWithNameAndSize(cf_name, 12);
CFRelease(cf_name);
if (!desc)
return out;
CTFontRef font = CTFontCreateWithFontDescriptor(desc, 0, nullptr);
CFRelease(desc);
if (!font)
return out;
CFDataRef data = CTFontCopyTable(font, kCTFontTableCFF, 0);
if (!data)
data = CTFontCopyTable(font, kCTFontTableHead, 0);
if (data)
{
CFIndex size = CFDataGetLength(data);
out.resize(size);
CFDataGetBytes(data, CFRangeMake(0, size), out.data());
CFRelease(data);
}
CFRelease(font);
return out;
}
#endif
#if !defined(_WIN32) && !defined(__APPLE__)
#include <fontconfig/fontconfig.h>
std::string font_loader::find_font_linux(const char* font_name)
{
FcInit();
FcPattern* pattern = FcNameParse(reinterpret_cast<const FcChar8*>(font_name));
if (!pattern)
return {};
FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
FcResult result;
FcPattern* match = FcFontMatch(nullptr, pattern, &result);
std::string out;
if (match)
{
FcChar8* file = nullptr;
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch)
out = reinterpret_cast<const char*>(file);
FcPatternDestroy(match);
}
FcPatternDestroy(pattern);
return out;
}
#endif
std::string font_loader::find_font_path(const char* font_name)
{
#if defined(_WIN32)
return find_font_windows(font_name);
#elif defined(__APPLE__)
(void)font_name;
return {};
#else
return find_font_linux(font_name);
#endif
}
ImFont* font_loader::load_font(const char* font_name, float size_px)
{
#if defined(__APPLE__)
std::vector<unsigned char> buf = load_font_macos(font_name);
if (buf.empty())
return nullptr;
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(
buf.data(),
static_cast<int>(buf.size()),
size_px
);
#else
std::string path = find_font_path(font_name);
if (path.empty())
return nullptr;
float scale = ImGui::GetIO().DisplayFramebufferScale.y;
return ImGui::GetIO().Fonts->AddFontFromFileTTF(
path.c_str(),
size_px * scale
);
#endif
}
void font_loader::push_default_font()
{
ImGui::PushFont(ImGui::GetDefaultFont(), clrsync::core::config::instance().font_size());
}
void font_loader::pop_font()
{
ImGui::PopFont();
}

View File

@@ -1,30 +0,0 @@
#ifndef CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP
#define CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP
#include <string>
#include <vector>
#include <imgui.h>
class font_loader
{
public:
font_loader() = default;
// Loads system font by name and returns an ImFont* or nullptr.
ImFont* load_font(const char* font_name, float size_px);
void push_default_font();
void pop_font();
private:
std::string find_font_path(const char* font_name);
#if defined(_WIN32)
static std::string find_font_windows(const char* font_name);
#elif defined(__APPLE__)
std::vector<unsigned char> load_font_macos(const char* font_name);
#else
std::string find_font_linux(const char* font_name);
#endif
};
#endif // CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP

View File

@@ -1,154 +0,0 @@
#include <string>
#include "GLFW/glfw3.h"
#include "gui/settings_window.hpp"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include "imgui_helpers.hpp"
#include "imgui_internal.h"
GLFWwindow * init_glfw()
{
if (!glfwInit()) return nullptr;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
GLFWwindow* w = glfwCreateWindow(1280, 720, "clrsync", nullptr, nullptr);
if (!w) return nullptr;
glfwMakeContextCurrent(w);
glfwSwapInterval(1);
return w;
}
void init_imgui(GLFWwindow* window, const std::string& ini_path)
{
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.IniFilename = ini_path.c_str();
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 130");
}
void begin_frame()
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
}
void render_menu_bar(about_window* about, settings_window* settings)
{
if (ImGui::BeginMainMenuBar())
{
if (ImGui::BeginMenu("File"))
{
if (ImGui::MenuItem("Settings"))
{
if (settings)
settings->show();
}
ImGui::Separator();
if (ImGui::MenuItem("Exit"))
{
// Will be handled by checking window should close
glfwSetWindowShouldClose(glfwGetCurrentContext(), GLFW_TRUE);
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help"))
{
if (ImGui::MenuItem("About"))
{
if (about)
about->show();
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
}
void setup_main_dockspace(bool& first_time)
{
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID);
constexpr ImGuiWindowFlags flags =
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoNavFocus |
ImGuiWindowFlags_MenuBar;
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0,0));
ImGui::Begin("MainDockSpace", nullptr, flags);
ImGui::PopStyleVar(3);
ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
if (first_time)
{
first_time = false;
ImGui::DockBuilderRemoveNode(dockspace_id);
ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace);
ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size);
ImGuiID center, right;
ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Right, 0.5f, &right, &center);
ImGuiDockNode* center_node = ImGui::DockBuilderGetNode(center);
if (center_node)
{
center_node->LocalFlags |= ImGuiDockNodeFlags_CentralNode;
}
ImGui::DockBuilderDockWindow("Color Schemes", right);
ImGui::DockBuilderDockWindow("Templates", center);
ImGui::DockBuilderDockWindow("Color Preview", center);
ImGui::DockBuilderFinish(dockspace_id);
}
ImGui::DockSpace(dockspace_id, ImVec2{0,0}, ImGuiDockNodeFlags_None);
ImGui::End();
}
void end_frame(GLFWwindow* window)
{
ImGui::Render();
int w, h;
glfwGetFramebufferSize(window, &w, &h);
glViewport(0, 0, w, h);
glClearColor(0.1f, 0.1f, 0.1f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
void shutdown(GLFWwindow* window)
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
}

View File

@@ -1,18 +0,0 @@
#ifndef CLRSYNC_IMGUI_HELPERS_HPP
#define CLRSYNC_IMGUI_HELPERS_HPP
#include "gui/about_window.hpp"
#include <string>
struct GLFWwindow;
class settings_window;
GLFWwindow * init_glfw();
void init_imgui(GLFWwindow* window, const std::string& ini_path);
void begin_frame();
void setup_main_dockspace(bool& first_time);
void end_frame(GLFWwindow* window);
void shutdown(GLFWwindow* window);
void render_menu_bar(about_window* about, settings_window* settings);
#endif // CLRSYNC_IMGUI_HELPERS_HPP

View File

@@ -0,0 +1,117 @@
#include "main_layout.hpp"
#include "imgui.h"
#include "imgui_internal.h"
namespace clrsync::gui::layout
{
void main_layout::render_menu_bar()
{
ImGuiViewport *vp = ImGui::GetMainViewport();
const float bar_height = 30.0f;
ImGui::SetNextWindowPos(vp->Pos);
ImGui::SetNextWindowSize(ImVec2(vp->Size.x, bar_height));
ImGui::SetNextWindowViewport(vp->ID);
ImGuiWindowFlags flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8, 2));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8, 3));
ImGui::Begin("##TopBar", nullptr, flags);
ImGuiStyle &style = ImGui::GetStyle();
style.FrameBorderSize = 1.0f;
const char *settings_label = "Settings";
const char *about_label = "About";
ImVec2 settings_size = ImGui::CalcTextSize(settings_label);
ImVec2 about_size = ImGui::CalcTextSize(about_label);
float total_width = settings_size.x + style.FramePadding.x * 2.0f + about_size.x +
style.FramePadding.x * 2.0f + style.ItemSpacing.x;
float pos_x = ImGui::GetWindowWidth() - total_width - style.WindowPadding.x;
float button_height = ImGui::GetFrameHeight();
float window_height = ImGui::GetWindowHeight();
float center_y = (window_height - button_height) * 0.5f;
ImGui::SetCursorPos(ImVec2(pos_x, center_y));
if (ImGui::Button(settings_label))
{
m_show_settings = true;
}
ImGui::SameLine();
ImGui::SetCursorPosY(center_y);
if (ImGui::Button(about_label))
{
m_show_about = true;
}
ImGui::End();
ImGui::PopStyleVar(4);
}
void main_layout::setup_dockspace(bool &first_time)
{
const ImGuiViewport *viewport = ImGui::GetMainViewport();
const float topbar_height = 32.0f;
ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x, viewport->Pos.y + topbar_height));
ImGui::SetNextWindowSize(ImVec2(viewport->Size.x, viewport->Size.y - topbar_height));
ImGui::SetNextWindowViewport(viewport->ID);
constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoNavFocus;
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8, 3));
ImGui::Begin("MainDockSpace", nullptr, flags);
ImGui::PopStyleVar(4);
ImGuiID dockspace_id = ImGui::GetID("MainDockSpace");
if (first_time)
{
first_time = false;
ImGui::DockBuilderRemoveNode(dockspace_id);
ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace);
ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size);
ImGuiID center, right;
ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Right, 0.5f, &right, &center);
ImGuiDockNode *center_node = ImGui::DockBuilderGetNode(center);
if (center_node)
{
center_node->LocalFlags |= ImGuiDockNodeFlags_CentralNode;
}
ImGui::DockBuilderDockWindow("Color Schemes", right);
ImGui::DockBuilderDockWindow("Color Preview", center);
ImGui::DockBuilderDockWindow("Templates", center);
ImGui::DockBuilderFinish(dockspace_id);
}
ImGui::DockSpace(dockspace_id, ImVec2{0, 0}, ImGuiDockNodeFlags_None);
ImGui::End();
}
} // namespace clrsync::gui::layout

View File

@@ -0,0 +1,28 @@
#ifndef CLRSYNC_GUI_LAYOUT_MAIN_LAYOUT_HPP
#define CLRSYNC_GUI_LAYOUT_MAIN_LAYOUT_HPP
namespace clrsync::gui::layout
{
class main_layout
{
public:
void setup_dockspace(bool &first_time);
void render_menu_bar();
bool should_show_about() const { return m_show_about; }
bool should_show_settings() const { return m_show_settings; }
void clear_actions()
{
m_show_about = false;
m_show_settings = false;
}
private:
bool m_show_about = false;
bool m_show_settings = false;
};
} // namespace clrsync::gui::layout
#endif // CLRSYNC_GUI_LAYOUT_MAIN_LAYOUT_HPP

View File

@@ -1,81 +1,108 @@
#include <iostream>
#include <memory>
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#include "core/common/error.hpp"
#include "core/common/utils.hpp"
#include "core/config/config.hpp"
#include "core/io/toml_file.hpp"
#include "core/utils.hpp"
#include "color_scheme_editor.hpp"
#include "gui/font_loader.hpp"
#include "gui/settings_window.hpp"
#include "imgui_helpers.hpp"
#include "template_editor.hpp"
#include "about_window.hpp"
#include "gui/backend/glfw_opengl.hpp"
#include "gui/layout/main_layout.hpp"
#include "gui/ui_manager.hpp"
#include "gui/views/about_window.hpp"
#include "gui/views/color_scheme_editor.hpp"
#include "gui/views/settings_window.hpp"
#include "gui/views/template_editor.hpp"
int main(int, char**)
int main(int, char **)
{
auto config_path = clrsync::core::get_default_config_path();
auto conf = std::make_unique<clrsync::core::io::toml_file>(config_path);
clrsync::core::config::instance().initialize(std::move(conf));
auto init_result = clrsync::core::config::instance().initialize(std::move(conf));
if (!init_result)
{
std::cerr << "Fatal error: " << init_result.error().description() << std::endl;
std::cerr
<< "Hint: Set CLRSYNC_CONFIG_PATH environment variable or ensure config exists at: "
<< config_path << std::endl;
return 1;
}
std::filesystem::path base = config_path;
static std::string ini_path = (base.parent_path() / "layout.ini").string();
bool first_time = !std::filesystem::exists(ini_path);
GLFWwindow* window = init_glfw();
if (!window) return 1;
auto backend = clrsync::gui::backend::glfw_opengl_backend();
auto window_config = clrsync::gui::backend::window_config();
window_config.title = "clrsync";
window_config.width = 1280;
window_config.height = 720;
window_config.decorated = true;
window_config.transparent_framebuffer = true;
printf("GLFV Version: %s\n", glfwGetVersionString());
std::cout << "GLFW runtime platform: ";
switch (glfwGetPlatform()) {
case GLFW_PLATFORM_WAYLAND: std::cout << "Wayland\n"; break;
case GLFW_PLATFORM_X11: std::cout << "X11\n"; break;
case GLFW_PLATFORM_COCOA: std::cout << "Cocoa\n"; break;
case GLFW_PLATFORM_WIN32: std::cout << "Win32\n"; break;
default: std::cout << "Unknown\n";
if (!backend.initialize(window_config))
{
std::cerr << "Failed to initialize backend." << std::endl;
return 1;
}
std::cout << "GLFW Version: " << backend.get_glfw_version() << std::endl;
std::cout << "GLFW runtime platform: " << backend.get_glfw_platform() << std::endl;
init_imgui(window, ini_path);
clrsync::gui::ui_manager ui_manager(&backend);
font_loader loader;
clrsync::gui::ui_config ui_cfg;
ui_cfg.ini_path = ini_path;
ui_cfg.enable_docking = true;
ui_cfg.enable_keyboard_nav = true;
ImFont* font =
loader.load_font(clrsync::core::config::instance().font().c_str(), clrsync::core::config::instance().font_size());
if (font)
ImGui::GetIO().FontDefault = font;
if (!ui_manager.initialize(ui_cfg))
{
std::cerr << "Failed to initialize UI manager." << std::endl;
return 1;
}
clrsync::gui::layout::main_layout main_layout;
color_scheme_editor colorEditor;
template_editor templateEditor;
template_editor templateEditor(&ui_manager);
about_window aboutWindow;
settings_window settingsWindow;
settings_window settingsWindow(&ui_manager);
colorEditor.set_template_editor(&templateEditor);
colorEditor.set_settings_window(&settingsWindow);
templateEditor.apply_current_palette(colorEditor.controller().current_palette());
settingsWindow.set_palette(colorEditor.controller().current_palette());
while (!glfwWindowShouldClose(window))
while (!backend.should_close())
{
glfwPollEvents();
loader.push_default_font();
begin_frame();
backend.begin_frame();
render_menu_bar(&aboutWindow, &settingsWindow);
setup_main_dockspace(first_time);
ui_manager.push_default_font();
ui_manager.begin_frame();
main_layout.render_menu_bar();
main_layout.setup_dockspace(first_time);
if (main_layout.should_show_about())
aboutWindow.show();
if (main_layout.should_show_settings())
settingsWindow.show();
main_layout.clear_actions();
templateEditor.render();
colorEditor.render_controls_and_colors();
colorEditor.render_preview();
templateEditor.render();
aboutWindow.render();
aboutWindow.render(colorEditor.controller().current_palette());
settingsWindow.render();
loader.pop_font();
end_frame(window);
ui_manager.pop_font();
ui_manager.end_frame();
backend.end_frame();
}
shutdown(window);
ui_manager.shutdown();
backend.shutdown();
return 0;
}

View File

@@ -0,0 +1,21 @@
#ifndef CLRSYNC_GUI_FILE_BROWSER_HPP
#define CLRSYNC_GUI_FILE_BROWSER_HPP
#include <string>
#include <vector>
namespace file_dialogs
{
std::string open_file_dialog(const std::string &title = "Open File",
const std::string &initial_path = "",
const std::vector<std::string> &filters = {});
std::string save_file_dialog(const std::string &title = "Save File",
const std::string &initial_path = "",
const std::vector<std::string> &filters = {});
std::string select_folder_dialog(const std::string &title = "Select Folder",
const std::string &initial_path = "");
} // namespace file_dialogs
#endif // CLRSYNC_GUI_FILE_BROWSER_HPP

View File

@@ -0,0 +1,31 @@
#ifndef CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP
#define CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP
#include <imgui.h>
#include <string>
#include <vector>
class font_loader
{
public:
font_loader() = default;
ImFont *load_font(const char *font_name, float size_px);
void push_default_font();
void pop_font();
std::vector<std::string> get_system_fonts();
private:
std::string find_font_path(const char *font_name);
#if defined(_WIN32)
static std::string find_font_windows(const char *font_name);
#elif defined(__APPLE__)
std::vector<unsigned char> load_font_macos(const char *font_name);
#else
std::string find_font_linux(const char *font_name);
#endif
};
#endif // CLRSYNC_GUI_SYSTEM_FONT_LOADER_HPP

View File

@@ -0,0 +1,133 @@
#ifdef __linux__
#include "gui/platform/file_browser.hpp"
#include <gtk/gtk.h>
#include <filesystem>
namespace file_dialogs
{
std::string open_file_dialog(const std::string &title, const std::string &initial_path,
const std::vector<std::string> &filters)
{
if (!gtk_init_check(nullptr, nullptr))
{
return "";
}
GtkFileChooserNative *native = gtk_file_chooser_native_new(
title.c_str(), nullptr, GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", "_Cancel");
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
if (!initial_path.empty())
{
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p))
{
if (std::filesystem::is_directory(p))
{
gtk_file_chooser_set_current_folder(chooser, initial_path.c_str());
}
else
{
gtk_file_chooser_set_current_folder(chooser, p.parent_path().c_str());
gtk_file_chooser_set_current_name(chooser, p.filename().c_str());
}
}
}
std::string result;
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)) == GTK_RESPONSE_ACCEPT)
{
char *filename = gtk_file_chooser_get_filename(chooser);
if (filename)
{
result = filename;
g_free(filename);
}
}
g_object_unref(native);
while (gtk_events_pending())
gtk_main_iteration();
return result;
}
std::string save_file_dialog(const std::string &title, const std::string &initial_path,
const std::vector<std::string> &filters)
{
if (!gtk_init_check(nullptr, nullptr))
{
return "";
}
GtkFileChooserNative *native = gtk_file_chooser_native_new(
title.c_str(), nullptr, GTK_FILE_CHOOSER_ACTION_SAVE, "_Save", "_Cancel");
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
if (!initial_path.empty())
{
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p.parent_path()))
{
gtk_file_chooser_set_current_folder(chooser, p.parent_path().c_str());
gtk_file_chooser_set_current_name(chooser, p.filename().c_str());
}
}
std::string result;
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)) == GTK_RESPONSE_ACCEPT)
{
char *filename = gtk_file_chooser_get_filename(chooser);
if (filename)
{
result = filename;
g_free(filename);
}
}
g_object_unref(native);
while (gtk_events_pending())
gtk_main_iteration();
return result;
}
std::string select_folder_dialog(const std::string &title, const std::string &initial_path)
{
if (!gtk_init_check(nullptr, nullptr))
{
return "";
}
GtkFileChooserNative *native = gtk_file_chooser_native_new(
title.c_str(), nullptr, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Select", "_Cancel");
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
if (!initial_path.empty() && std::filesystem::exists(initial_path))
{
gtk_file_chooser_set_current_folder(chooser, initial_path.c_str());
}
std::string result;
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)) == GTK_RESPONSE_ACCEPT)
{
char *filename = gtk_file_chooser_get_filename(chooser);
if (filename)
{
result = filename;
g_free(filename);
}
}
g_object_unref(native);
while (gtk_events_pending())
gtk_main_iteration();
return result;
}
} // namespace file_dialogs
#endif

View File

@@ -0,0 +1,95 @@
#ifdef __linux__
#include "core/config/config.hpp"
#include "gui/platform/font_loader.hpp"
#include "imgui_internal.h"
#include <algorithm>
#include <fontconfig/fontconfig.h>
#include <imgui.h>
std::string font_loader::find_font_linux(const char *font_name)
{
FcInit();
FcPattern *pattern = FcNameParse(reinterpret_cast<const FcChar8 *>(font_name));
if (!pattern)
return {};
FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
FcResult result;
FcPattern *match = FcFontMatch(nullptr, pattern, &result);
std::string out;
if (match)
{
FcChar8 *file = nullptr;
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch)
out = reinterpret_cast<const char *>(file);
FcPatternDestroy(match);
}
FcPatternDestroy(pattern);
return out;
}
std::string font_loader::find_font_path(const char *font_name)
{
return find_font_linux(font_name);
}
ImFont *font_loader::load_font(const char *font_name, float size_px)
{
std::string path = find_font_path(font_name);
if (path.empty())
return nullptr;
float scale = ImGui::GetIO().DisplayFramebufferScale.y;
return ImGui::GetIO().Fonts->AddFontFromFileTTF(path.c_str(), size_px * scale);
}
void font_loader::push_default_font()
{
ImGui::PushFont(ImGui::GetDefaultFont(), clrsync::core::config::instance().font_size());
}
void font_loader::pop_font()
{
ImGui::PopFont();
}
std::vector<std::string> font_loader::get_system_fonts()
{
std::vector<std::string> fonts;
FcInit();
FcPattern *pattern = FcPatternCreate();
FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, nullptr);
FcFontSet *fs = FcFontList(nullptr, pattern, os);
if (fs)
{
for (int i = 0; i < fs->nfont; i++)
{
FcChar8 *family = nullptr;
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch)
{
std::string font_name = reinterpret_cast<const char *>(family);
if (std::find(fonts.begin(), fonts.end(), font_name) == fonts.end())
fonts.push_back(font_name);
}
}
FcFontSetDestroy(fs);
}
FcObjectSetDestroy(os);
FcPatternDestroy(pattern);
std::sort(fonts.begin(), fonts.end());
return fonts;
}
#endif

View File

@@ -0,0 +1,78 @@
#ifdef __APPLE__
#include "gui/platform/file_browser.hpp"
#include <filesystem>
#include <Cocoa/Cocoa.h>
namespace file_dialogs {
std::string open_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:YES];
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string save_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters) {
@autoreleasepool {
NSSavePanel* panel = [NSSavePanel savePanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
if (!initial_path.empty()) {
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p.parent_path())) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:p.parent_path().c_str()]];
[panel setDirectoryURL:url];
[panel setNameFieldStringValue:[NSString stringWithUTF8String:p.filename().c_str()]];
}
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [panel URL];
return std::string([[url path] UTF8String]);
}
}
return "";
}
std::string select_folder_dialog(const std::string& title,
const std::string& initial_path) {
@autoreleasepool {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:NO];
if (!initial_path.empty()) {
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
[panel setDirectoryURL:url];
}
if ([panel runModal] == NSModalResponseOK) {
NSURL* url = [[panel URLs] objectAtIndex:0];
return std::string([[url path] UTF8String]);
}
}
return "";
}
}
#endif

View File

@@ -0,0 +1,115 @@
#ifdef __APPLE__
#include "core/config/config.hpp"
#include "gui/platform/font_loader.hpp"
#include "imgui_internal.h"
#include <CoreText/CoreText.h>
#include <algorithm>
#include <imgui.h>
std::vector<unsigned char> font_loader::load_font_macos(const char *font_name)
{
std::vector<unsigned char> out;
CFStringRef cf_name = CFStringCreateWithCString(nullptr, font_name, kCFStringEncodingUTF8);
if (!cf_name)
return out;
CTFontDescriptorRef desc = CTFontDescriptorCreateWithNameAndSize(cf_name, 12);
CFRelease(cf_name);
if (!desc)
return out;
CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(desc, kCTFontURLAttribute);
CFRelease(desc);
if (!url)
return out;
CFDataRef data = nullptr;
Boolean success = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, url, &data,
nullptr, nullptr, nullptr);
CFRelease(url);
if (success && data)
{
CFIndex size = CFDataGetLength(data);
if (size > 100)
{
out.resize(size);
CFDataGetBytes(data, CFRangeMake(0, size), out.data());
}
CFRelease(data);
}
return out;
}
std::string font_loader::find_font_path(const char *font_name)
{
(void)font_name;
return {};
}
ImFont *font_loader::load_font(const char *font_name, float size_px)
{
std::vector<unsigned char> buf = load_font_macos(font_name);
if (buf.empty())
return nullptr;
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(buf.data(), static_cast<int>(buf.size()),
size_px);
}
void font_loader::push_default_font()
{
ImGui::PushFont(ImGui::GetDefaultFont(), clrsync::core::config::instance().font_size());
}
void font_loader::pop_font()
{
ImGui::PopFont();
}
std::vector<std::string> font_loader::get_system_fonts()
{
std::vector<std::string> fonts;
CTFontCollectionRef collection = CTFontCollectionCreateFromAvailableFonts(nullptr);
if (collection)
{
CFArrayRef fontDescriptors = CTFontCollectionCreateMatchingFontDescriptors(collection);
CFRelease(collection);
if (fontDescriptors)
{
CFIndex count = CFArrayGetCount(fontDescriptors);
for (CFIndex i = 0; i < count; i++)
{
CTFontDescriptorRef descriptor =
(CTFontDescriptorRef)CFArrayGetValueAtIndex(fontDescriptors, i);
CFStringRef fontName = (CFStringRef)CTFontDescriptorCopyAttribute(
descriptor, kCTFontDisplayNameAttribute);
if (fontName)
{
char buffer[256];
if (CFStringGetCString(fontName, buffer, sizeof(buffer), kCFStringEncodingUTF8))
{
std::string font_name = buffer;
if (std::find(fonts.begin(), fonts.end(), font_name) == fonts.end())
fonts.push_back(font_name);
}
CFRelease(fontName);
}
}
CFRelease(fontDescriptors);
}
}
std::sort(fonts.begin(), fonts.end());
return fonts;
}
#endif

View File

@@ -0,0 +1,167 @@
#ifdef _WIN32
// clang-format off
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commdlg.h>
#include <shlobj.h>
#include <shlwapi.h>
// clang-format on
#include "gui/platform/file_browser.hpp"
#include <filesystem>
namespace file_dialogs
{
std::string open_file_dialog(const std::string &title, const std::string &initial_path,
const std::vector<std::string> &filters)
{
OPENFILENAMEA ofn;
char file[MAX_PATH] = "";
std::string filter_str = "All Files (*.*)\0*.*\0";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFile = file;
ofn.nMaxFile = sizeof(file);
ofn.lpstrFilter = filter_str.c_str();
ofn.nFilterIndex = 1;
ofn.lpstrTitle = title.c_str();
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
if (!initial_path.empty() && std::filesystem::exists(initial_path))
{
std::filesystem::path p(initial_path);
if (std::filesystem::is_directory(p))
{
ofn.lpstrInitialDir = initial_path.c_str();
}
else
{
std::string dir = p.parent_path().string();
std::string name = p.filename().string();
ofn.lpstrInitialDir = dir.c_str();
strncpy(file, name.c_str(), sizeof(file) - 1);
}
}
if (GetOpenFileNameA(&ofn))
{
return std::string(file);
}
return "";
}
std::string save_file_dialog(const std::string &title, const std::string &initial_path,
const std::vector<std::string> &filters)
{
OPENFILENAMEA ofn;
char file[MAX_PATH] = "";
std::string filter_str = "All Files\0*.*\0\0";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFile = file;
ofn.nMaxFile = sizeof(file);
ofn.lpstrFilter = filter_str.c_str();
ofn.nFilterIndex = 1;
ofn.lpstrTitle = title.c_str();
ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR;
if (!initial_path.empty())
{
std::filesystem::path p(initial_path);
if (std::filesystem::exists(p) && std::filesystem::is_directory(p))
{
ofn.lpstrInitialDir = initial_path.c_str();
}
else
{
std::string dir = p.parent_path().string();
std::string name = p.filename().string();
if (std::filesystem::exists(dir))
{
ofn.lpstrInitialDir = dir.c_str();
strncpy(file, name.c_str(), sizeof(file) - 1);
}
}
}
if (GetSaveFileNameA(&ofn))
{
return std::string(file);
}
return "";
}
std::string select_folder_dialog(const std::string &title, const std::string &initial_path)
{
IFileOpenDialog *pFileOpen;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog,
reinterpret_cast<void **>(&pFileOpen));
if (SUCCEEDED(hr))
{
DWORD dwFlags;
if (SUCCEEDED(pFileOpen->GetOptions(&dwFlags)))
{
pFileOpen->SetOptions(dwFlags | FOS_PICKFOLDERS);
}
std::wstring wtitle(title.begin(), title.end());
pFileOpen->SetTitle(wtitle.c_str());
if (!initial_path.empty() && std::filesystem::exists(initial_path))
{
IShellItem *psi = NULL;
std::wstring winitial(initial_path.begin(), initial_path.end());
hr = SHCreateItemFromParsingName(winitial.c_str(), NULL, IID_IShellItem, (void **)&psi);
if (SUCCEEDED(hr))
{
pFileOpen->SetFolder(psi);
psi->Release();
}
}
hr = pFileOpen->Show(GetActiveWindow());
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
if (SUCCEEDED(hr))
{
std::wstring wpath(pszFilePath);
int size = WideCharToMultiByte(CP_UTF8, 0, wpath.c_str(), -1, nullptr, 0,
nullptr, nullptr);
std::string result(size - 1, 0);
WideCharToMultiByte(CP_UTF8, 0, wpath.c_str(), -1, &result[0], size, nullptr,
nullptr);
CoTaskMemFree(pszFilePath);
pItem->Release();
pFileOpen->Release();
return result;
}
pItem->Release();
}
}
pFileOpen->Release();
}
return "";
}
} // namespace file_dialogs
#endif

View File

@@ -0,0 +1,170 @@
#ifdef _WIN32
#include "core/config/config.hpp"
#include "gui/platform/font_loader.hpp"
#include "imgui_internal.h"
#include <algorithm>
#include <imgui.h>
#include <windows.h>
#include <winreg.h>
static std::string search_registry_for_font(HKEY root_key, const char *subkey,
const std::string &font_name_lower,
const char *default_font_dir)
{
HKEY hKey;
LONG result = RegOpenKeyExA(root_key, subkey, 0, KEY_READ, &hKey);
if (result != ERROR_SUCCESS)
return {};
char value_name[512];
BYTE value_data[512];
DWORD value_name_size, value_data_size, type;
DWORD index = 0;
std::string found_path;
while (true)
{
value_name_size = sizeof(value_name);
value_data_size = sizeof(value_data);
result = RegEnumValueA(hKey, index++, value_name, &value_name_size, nullptr, &type,
value_data, &value_data_size);
if (result != ERROR_SUCCESS)
break;
if (type != REG_SZ)
continue;
std::string reg_font_name = value_name;
std::transform(reg_font_name.begin(), reg_font_name.end(), reg_font_name.begin(),
::tolower);
std::string reg_font_name_clean = reg_font_name;
size_t type_pos = reg_font_name_clean.find(" (");
if (type_pos != std::string::npos)
reg_font_name_clean = reg_font_name_clean.substr(0, type_pos);
if (reg_font_name_clean == font_name_lower)
{
std::string font_file = reinterpret_cast<char *>(value_data);
// If path is not absolute, prepend default font directory
if (font_file.find(":\\") == std::string::npos)
{
found_path = std::string(default_font_dir) + "\\" + font_file;
}
else
{
found_path = font_file;
}
break;
}
}
RegCloseKey(hKey);
return found_path;
}
std::string font_loader::find_font_windows(const char *font_name)
{
std::string font_name_lower = font_name;
std::transform(font_name_lower.begin(), font_name_lower.end(), font_name_lower.begin(),
::tolower);
char windows_dir[MAX_PATH];
GetWindowsDirectoryA(windows_dir, MAX_PATH);
std::string system_fonts_dir = std::string(windows_dir) + "\\Fonts";
// First, try system-wide fonts (HKEY_LOCAL_MACHINE)
std::string path = search_registry_for_font(
HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
font_name_lower, system_fonts_dir.c_str());
if (!path.empty())
return path;
// If not found, try per-user fonts (HKEY_CURRENT_USER)
char local_appdata[MAX_PATH];
if (GetEnvironmentVariableA("LOCALAPPDATA", local_appdata, MAX_PATH) > 0)
{
std::string user_fonts_dir = std::string(local_appdata) + "\\Microsoft\\Windows\\Fonts";
path = search_registry_for_font(HKEY_CURRENT_USER,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
font_name_lower, user_fonts_dir.c_str());
}
return path;
}
std::string font_loader::find_font_path(const char *font_name)
{
return find_font_windows(font_name);
}
ImFont *font_loader::load_font(const char *font_name, float size_px)
{
std::string path = find_font_path(font_name);
if (path.empty())
return nullptr;
float scale = ImGui::GetIO().DisplayFramebufferScale.y;
return ImGui::GetIO().Fonts->AddFontFromFileTTF(path.c_str(), size_px * scale);
}
void font_loader::push_default_font()
{
ImGui::PushFont(ImGui::GetDefaultFont(), clrsync::core::config::instance().font_size());
}
void font_loader::pop_font()
{
ImGui::PopFont();
}
std::vector<std::string> font_loader::get_system_fonts()
{
std::vector<std::string> fonts;
auto enumerate_registry_fonts = [&fonts](HKEY root_key, const char *subkey) {
HKEY hKey;
if (RegOpenKeyExA(root_key, subkey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
return;
char value_name[512];
DWORD value_name_size;
DWORD index = 0;
while (true)
{
value_name_size = sizeof(value_name);
LONG result = RegEnumValueA(hKey, index++, value_name, &value_name_size, nullptr,
nullptr, nullptr, nullptr);
if (result != ERROR_SUCCESS)
break;
std::string font_name = value_name;
size_t pos = font_name.find(" (");
if (pos != std::string::npos)
font_name = font_name.substr(0, pos);
if (std::find(fonts.begin(), fonts.end(), font_name) == fonts.end())
fonts.push_back(font_name);
}
RegCloseKey(hKey);
};
enumerate_registry_fonts(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
enumerate_registry_fonts(HKEY_CURRENT_USER,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
std::sort(fonts.begin(), fonts.end());
return fonts;
}
#endif

View File

@@ -1,201 +0,0 @@
#include "settings_window.hpp"
#include "core/config/config.hpp"
#include "gui/font_loader.hpp"
#include "imgui.h"
#include <cstring>
settings_window::settings_window()
: m_font_size(14)
{
m_default_theme[0] = '\0';
m_palettes_path[0] = '\0';
m_font[0] = '\0';
load_settings();
}
void settings_window::render()
{
if (!m_visible)
return;
ImGui::SetNextWindowSize(ImVec2(600, 400), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Settings", &m_visible))
{
ImGui::Text("General Settings");
ImGui::Separator();
ImGui::Spacing();
ImGui::Text("Default Theme:");
ImGui::SameLine();
ImGui::SetNextItemWidth(300.0f);
ImGui::InputText("##default_theme", m_default_theme, sizeof(m_default_theme));
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("The default color scheme to load on startup");
}
ImGui::Spacing();
ImGui::Text("Palettes Path:");
ImGui::SetNextItemWidth(-FLT_MIN);
ImGui::InputText("##palettes_path", m_palettes_path, sizeof(m_palettes_path));
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("Directory where color palettes are stored\nSupports ~ for home directory");
}
ImGui::Spacing();
ImGui::Text("Font:");
ImGui::SameLine();
ImGui::SetNextItemWidth(300.0f);
ImGui::InputText("##font", m_font, sizeof(m_font));
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("Font");
}
ImGui::Spacing();
ImGui::Text("Font Size:");
ImGui::SameLine();
ImGui::SetNextItemWidth(100.0f);
ImGui::InputInt("##font_size", &m_font_size, 1, 1);
if (m_font_size < 8) m_font_size = 8;
if (m_font_size > 48) m_font_size = 48;
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("Font size");
}
ImGui::Spacing();
ImGui::Spacing();
if (!m_error_message.empty())
{
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.3f, 0.3f, 1.0f));
ImGui::TextWrapped("%s", m_error_message.c_str());
ImGui::PopStyleColor();
ImGui::Spacing();
}
ImGui::Separator();
ImGui::Spacing();
if (ImGui::Button("OK", ImVec2(120, 0)))
{
apply_settings();
m_visible = false;
m_error_message = "";
}
ImGui::SameLine();
if (ImGui::Button("Apply", ImVec2(120, 0)))
{
apply_settings();
}
ImGui::SameLine();
if (ImGui::Button("Reset to Defaults", ImVec2(150, 0)))
{
strncpy(m_default_theme, "dark", sizeof(m_default_theme));
strncpy(m_palettes_path, "~/.config/clrsync/palettes", sizeof(m_palettes_path));
strncpy(m_font, "JetBrains Mono Nerd Font", sizeof(m_font));
m_font_size = 14;
m_error_message = "";
}
ImGui::SameLine();
if (ImGui::Button("Cancel", ImVec2(120, 0)))
{
load_settings();
m_visible = false;
m_error_message = "";
}
}
ImGui::End();
}
void settings_window::load_settings()
{
try
{
auto& cfg = clrsync::core::config::instance();
std::string default_theme = cfg.default_theme();
strncpy(m_default_theme, default_theme.c_str(), sizeof(m_default_theme) - 1);
m_default_theme[sizeof(m_default_theme) - 1] = '\0';
std::string palettes_path = cfg.palettes_path();
strncpy(m_palettes_path, palettes_path.c_str(), sizeof(m_palettes_path) - 1);
m_palettes_path[sizeof(m_palettes_path) - 1] = '\0';
std::string font = cfg.font();
strncpy(m_font, font.c_str(), sizeof(m_font) - 1);
m_font[sizeof(m_font) - 1] = '\0';
m_font_size = cfg.font_size();
m_error_message = "";
}
catch (const std::exception& e)
{
m_error_message = std::string("Failed to load settings: ") + e.what();
// Set defaults on error
strncpy(m_default_theme, "dark", sizeof(m_default_theme));
strncpy(m_palettes_path, "~/.config/clrsync/palettes", sizeof(m_palettes_path));
strncpy(m_font, "JetBrains Mono Nerd Font", sizeof(m_font));
m_font_size = 14;
}
}
void settings_window::apply_settings()
{
try
{
auto& cfg = clrsync::core::config::instance();
if (strlen(m_default_theme) == 0)
{
m_error_message = "Default theme cannot be empty";
return;
}
if (strlen(m_palettes_path) == 0)
{
m_error_message = "Palettes path cannot be empty";
return;
}
if (strlen(m_font) == 0)
{
m_error_message = "Font cannot be empty";
return;
}
if (m_font_size < 8 || m_font_size > 48)
{
m_error_message = "Font size must be between 8 and 48";
return;
}
cfg.set_default_theme(m_default_theme);
cfg.set_palettes_path(m_palettes_path);
cfg.set_font(m_font);
cfg.set_font_size(m_font_size);
font_loader fn_loader;
auto font = fn_loader.load_font(m_font, m_font_size);
if (font)
ImGui::GetIO().FontDefault = font;
m_error_message = "";
}
catch (const std::exception& e)
{
m_error_message = std::string("Failed to apply settings: ") + e.what();
}
}

View File

@@ -1,30 +0,0 @@
#ifndef CLRSYNC_GUI_SETTINGS_WINDOW_HPP
#define CLRSYNC_GUI_SETTINGS_WINDOW_HPP
#include <string>
class settings_window
{
public:
settings_window();
void render();
void show() { m_visible = true; }
void hide() { m_visible = false; }
bool is_visible() const { return m_visible; }
private:
void load_settings();
void save_settings();
void apply_settings();
bool m_visible{false};
char m_default_theme[128];
char m_palettes_path[512];
char m_font[128];
int m_font_size;
std::string m_error_message;
};
#endif // CLRSYNC_GUI_SETTINGS_WINDOW_HPP

View File

@@ -1,39 +0,0 @@
#include "template_controller.hpp"
#include "core/config/config.hpp"
template_controller::template_controller()
{
m_templates = m_template_manager.templates();
}
void template_controller::set_template_enabled(const std::string& key, bool enabled)
{
auto it = m_templates.find(key);
if (it != m_templates.end()) {
it->second.set_enabled(enabled);
clrsync::core::config::instance().update_template(key, it->second);
}
}
void template_controller::set_template_output_path(const std::string& key, const std::string& path)
{
auto it = m_templates.find(key);
if (it != m_templates.end()) {
it->second.set_output_path(path);
clrsync::core::config::instance().update_template(key, it->second);
}
}
void template_controller::set_template_reload_command(const std::string& key, const std::string& cmd)
{
auto it = m_templates.find(key);
if (it != m_templates.end()) {
it->second.set_reload_command(cmd);
clrsync::core::config::instance().update_template(key, it->second);
}
}
void template_controller::refresh()
{
m_templates = m_template_manager.templates();
}

View File

@@ -1,457 +0,0 @@
#include "template_editor.hpp"
#include "core/config/config.hpp"
#include "core/theme/theme_template.hpp"
#include "imgui.h"
#include <filesystem>
#include <fstream>
#include <ranges>
template_editor::template_editor() : m_template_name("new_template")
{
TextEditor::LanguageDefinition lang;
lang.mName = "Template";
lang.mCommentStart = "/*";
lang.mCommentEnd = "*/";
lang.mSingleLineComment = "#";
lang.mTokenRegexStrings.push_back(std::make_pair<std::string, TextEditor::PaletteIndex>(
"\\{[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)?\\}",
TextEditor::PaletteIndex::KnownIdentifier));
lang.mTokenRegexStrings.push_back(std::make_pair<std::string, TextEditor::PaletteIndex>(
"\"([^\"]*)\"", TextEditor::PaletteIndex::String));
lang.mTokenRegexStrings.push_back(std::make_pair<std::string, TextEditor::PaletteIndex>(
"'([^']*)'", TextEditor::PaletteIndex::String));
m_editor.SetLanguageDefinition(lang);
m_editor.SetText("# Enter your template here\n# Use {color_key} for color variables\n# "
"Examples: {color.hex}, {color.rgb}, {color.r}\n\n");
m_editor.SetShowWhitespaces(false);
}
void template_editor::apply_current_palette(const clrsync::core::palette &pal)
{
auto colors = pal.colors();
if (colors.empty())
return;
auto get_color_u32 = [&](const std::string &key, const std::string &fallback = "") -> uint32_t {
auto it = colors.find(key);
if (it == colors.end() && !fallback.empty())
{
it = colors.find(fallback);
}
if (it != colors.end())
{
const auto &col = it->second;
const uint32_t hex = col.hex();
// Convert from RRGGBBAA to AABBGGRR (ImGui format)
const uint32_t r = (hex >> 24) & 0xFF;
const uint32_t g = (hex >> 16) & 0xFF;
const uint32_t b = (hex >> 8) & 0xFF;
const uint32_t a = hex & 0xFF;
return (a << 24) | (b << 16) | (g << 8) | r;
}
return 0xFFFFFFFF;
};
auto palette = m_editor.GetPalette();
palette[int(TextEditor::PaletteIndex::Default)] = get_color_u32("editor_main", "foreground");
palette[int(TextEditor::PaletteIndex::Keyword)] = get_color_u32("editor_command", "accent");
palette[int(TextEditor::PaletteIndex::Number)] = get_color_u32("editor_warning", "warning");
palette[int(TextEditor::PaletteIndex::String)] = get_color_u32("editor_string", "success");
palette[int(TextEditor::PaletteIndex::CharLiteral)] = get_color_u32("editor_string", "success");
palette[int(TextEditor::PaletteIndex::Punctuation)] =
get_color_u32("editor_main", "foreground");
palette[int(TextEditor::PaletteIndex::Preprocessor)] =
get_color_u32("editor_emphasis", "accent");
palette[int(TextEditor::PaletteIndex::Identifier)] = get_color_u32("editor_main", "foreground");
palette[int(TextEditor::PaletteIndex::KnownIdentifier)] = get_color_u32("editor_link", "info");
palette[int(TextEditor::PaletteIndex::PreprocIdentifier)] =
get_color_u32("editor_link", "info");
palette[int(TextEditor::PaletteIndex::Comment)] =
get_color_u32("editor_comment", "editor_inactive");
palette[int(TextEditor::PaletteIndex::MultiLineComment)] =
get_color_u32("editor_comment", "editor_inactive");
palette[int(TextEditor::PaletteIndex::Background)] =
get_color_u32("editor_background", "background");
palette[int(TextEditor::PaletteIndex::Cursor)] = get_color_u32("cursor", "accent");
palette[int(TextEditor::PaletteIndex::Selection)] =
get_color_u32("editor_selected", "surface_variant");
palette[int(TextEditor::PaletteIndex::ErrorMarker)] = get_color_u32("editor_error", "error");
palette[int(TextEditor::PaletteIndex::Breakpoint)] = get_color_u32("editor_error", "error");
palette[int(TextEditor::PaletteIndex::LineNumber)] =
get_color_u32("editor_line_number", "editor_inactive");
palette[int(TextEditor::PaletteIndex::CurrentLineFill)] = get_color_u32("surface_variant");
palette[int(TextEditor::PaletteIndex::CurrentLineFillInactive)] = get_color_u32("surface");
palette[int(TextEditor::PaletteIndex::CurrentLineEdge)] =
get_color_u32("border_focused", "border");
m_editor.SetPalette(palette);
}
void template_editor::render()
{
ImGui::Begin("Templates");
render_controls();
ImGui::Separator();
const float panel_width = ImGui::GetContentRegionAvail().x;
constexpr float left_panel_width = 200.0f;
const float right_panel_width = panel_width - left_panel_width - 10;
ImGui::BeginChild("TemplateList", ImVec2(left_panel_width, 0), true);
render_template_list();
ImGui::EndChild();
ImGui::SameLine();
ImGui::BeginChild("EditorPanel", ImVec2(right_panel_width, 0), false);
render_editor();
ImGui::EndChild();
ImGui::End();
}
void template_editor::render_controls()
{
if (ImGui::Button("New Template"))
{
new_template();
}
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyPressed(ImGuiKey_S))
{
save_template();
}
ImGui::SameLine();
if (ImGui::Button("Save"))
{
save_template();
}
ImGui::SameLine();
ImGui::Text("Template Name:");
ImGui::SameLine();
ImGui::SetNextItemWidth(150.0f);
char name_buf[256] = {0};
snprintf(name_buf, sizeof(name_buf), "%s", m_template_name.c_str());
if (ImGui::InputText("##template_name", name_buf, sizeof(name_buf)))
{
m_template_name = name_buf;
if (!m_template_name.empty())
{
m_validation_error = "";
}
}
ImGui::SameLine();
if (ImGui::Checkbox("Enabled", &m_enabled))
{
if (m_is_editing_existing)
{
m_template_controller.set_template_enabled(m_template_name, m_enabled);
}
}
ImGui::Text("Output Path:");
ImGui::SameLine();
ImGui::SetNextItemWidth(-FLT_MIN);
char path_buf[512] = {0};
snprintf(path_buf, sizeof(path_buf), "%s", m_output_path.c_str());
if (ImGui::InputText("##output_path", path_buf, sizeof(path_buf)))
{
m_output_path = path_buf;
if (!m_output_path.empty())
{
m_validation_error = "";
}
if (m_is_editing_existing)
{
m_template_controller.set_template_output_path(m_template_name, m_output_path);
}
}
ImGui::Text("Reload Command:");
ImGui::SameLine();
ImGui::SetNextItemWidth(-FLT_MIN);
char reload_buf[512] = {0};
snprintf(reload_buf, sizeof(reload_buf), "%s", m_reload_command.c_str());
if (ImGui::InputText("##reload_cmd", reload_buf, sizeof(reload_buf)))
{
m_reload_command = reload_buf;
if (m_is_editing_existing)
{
m_template_controller.set_template_reload_command(m_template_name, m_reload_command);
}
}
if (!m_validation_error.empty())
{
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.3f, 0.3f, 1.0f));
ImGui::TextWrapped("%s", m_validation_error.c_str());
ImGui::PopStyleColor();
}
}
void template_editor::render_editor()
{
if (!m_is_editing_existing)
{
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.4f, 0.8f, 0.4f, 1.0f));
ImGui::Text("New Template");
ImGui::PopStyleColor();
}
else
{
ImGui::Text("%s", m_template_name.c_str());
auto trim_right = [](const std::string &s) -> std::string {
size_t end = s.find_last_not_of("\r\n");
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
};
std::string current_content = trim_right(m_editor.GetText());
std::string saved_content = trim_right(m_saved_content);
m_has_unsaved_changes = (current_content != saved_content);
if (m_has_unsaved_changes)
{
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.6f, 0.2f, 1.0f));
ImGui::Text("");
ImGui::PopStyleColor();
}
}
ImGui::Separator();
m_editor.Render("##TemplateEditor", ImVec2(0, 0), true);
}
void template_editor::render_template_list()
{
ImGui::Text("Templates");
ImGui::Separator();
if (!m_is_editing_existing)
{
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.4f, 0.8f, 0.4f, 1.0f));
ImGui::Selectable("* New Template *", true);
ImGui::PopStyleColor();
ImGui::Separator();
}
const auto &templates = m_template_controller.templates();
for (const auto &key : templates | std::views::keys)
{
const bool selected = (m_template_name == key && m_is_editing_existing);
if (ImGui::Selectable(key.c_str(), selected))
{
load_template(key);
}
}
}
bool template_editor::is_valid_path(const std::string &path)
{
const std::string invalid_chars = "<>|\"";
for (const char c : invalid_chars)
{
if (path.find(c) != std::string::npos)
{
return false;
}
}
if (path.find_first_not_of(" \t\n\r./\\") == std::string::npos)
{
return false;
}
try
{
std::filesystem::path fs_path(path);
const auto parent = fs_path.parent_path();
if (parent.empty())
{
return false;
}
if (!parent.empty() && !std::filesystem::exists(parent))
{
if (parent.string().find_first_of("<>|\"") != std::string::npos)
{
return false;
}
}
const auto filename = fs_path.filename().string();
if (filename.empty() || filename == "." || filename == "..")
{
return false;
}
return true;
}
catch (...)
{
return false;
}
}
void template_editor::save_template()
{
std::string trimmed_name = m_template_name;
trimmed_name.erase(0, trimmed_name.find_first_not_of(" \t\n\r"));
trimmed_name.erase(trimmed_name.find_last_not_of(" \t\n\r") + 1);
std::string trimmed_path = m_output_path;
trimmed_path.erase(0, trimmed_path.find_first_not_of(" \t\n\r"));
trimmed_path.erase(trimmed_path.find_last_not_of(" \t\n\r") + 1);
if (trimmed_name.empty())
{
m_validation_error = "Error: Template name cannot be empty!";
return;
}
if (trimmed_path.empty())
{
m_validation_error = "Error: Output path cannot be empty!";
return;
}
if (!is_valid_path(trimmed_path))
{
m_validation_error =
"Error: Output path is invalid! Must be a valid file path with directory.";
return;
}
m_validation_error = "";
try
{
auto &cfg = clrsync::core::config::instance();
std::string palettes_path = cfg.palettes_path();
std::filesystem::path templates_dir =
std::filesystem::path(palettes_path).parent_path() / "templates";
if (!std::filesystem::exists(templates_dir))
{
std::filesystem::create_directories(templates_dir);
}
std::filesystem::path template_file;
if (m_is_editing_existing)
{
const auto &existing_template = cfg.template_by_name(trimmed_name);
template_file = existing_template.template_path();
}
else
{
template_file = templates_dir / trimmed_name;
}
std::string template_content = m_editor.GetText();
std::ofstream out(template_file);
if (out.is_open())
{
out << template_content;
out.close();
}
clrsync::core::theme_template tmpl(trimmed_name, template_file.string(), trimmed_path);
tmpl.set_reload_command(m_reload_command);
tmpl.set_enabled(m_enabled);
cfg.update_template(trimmed_name, tmpl);
m_template_name = trimmed_name;
m_output_path = trimmed_path;
m_is_editing_existing = true;
m_saved_content = m_editor.GetText();
m_has_unsaved_changes = false;
refresh_templates();
}
catch (const std::exception &e)
{
m_validation_error = std::string("Error saving template: ") + e.what();
}
}
void template_editor::load_template(const std::string &name)
{
const auto &templates = m_template_controller.templates();
auto it = templates.find(name);
if (it != templates.end())
{
const auto &tmpl = it->second;
m_template_name = name;
m_output_path = tmpl.output_path();
m_reload_command = tmpl.reload_command();
m_enabled = tmpl.enabled();
m_is_editing_existing = true;
m_validation_error = "";
try
{
std::ifstream in(tmpl.template_path());
if (in.is_open())
{
std::string content;
std::string line;
while (std::getline(in, line))
{
content += line + "\n";
}
in.close();
m_editor.SetText(content);
m_saved_content = content;
m_has_unsaved_changes = false;
}
}
catch (const std::exception &e)
{
m_validation_error = std::string("Error loading template: ") + e.what();
}
}
}
void template_editor::new_template()
{
m_template_name = "new_template";
std::string default_content =
"# Enter your template here\n# Use {color_key} for color variables\n# "
"Examples: {color.hex}, {color.rgb}, {color.r}\n\n";
m_editor.SetText(default_content);
m_saved_content = default_content;
m_output_path = "";
m_reload_command = "";
m_enabled = true;
m_is_editing_existing = false;
m_validation_error = "";
m_has_unsaved_changes = false;
}
void template_editor::refresh_templates()
{
m_template_controller.refresh();
}

View File

@@ -1,42 +0,0 @@
#ifndef CLRSYNC_GUI_TEMPLATE_EDITOR_HPP
#define CLRSYNC_GUI_TEMPLATE_EDITOR_HPP
#include "template_controller.hpp"
#include <core/palette/palette.hpp>
#include "color_text_edit/TextEditor.h"
#include <string>
class template_editor
{
public:
template_editor();
void render();
void apply_current_palette(const clrsync::core::palette& pal);
private:
void render_controls();
void render_editor();
void render_template_list();
void save_template();
void load_template(const std::string &name);
void new_template();
void refresh_templates();
bool is_valid_path(const std::string &path);
template_controller m_template_controller;
TextEditor m_editor;
std::string m_template_name;
std::string m_output_path;
std::string m_reload_command;
std::string m_validation_error;
std::string m_saved_content;
bool m_has_unsaved_changes = false;
bool m_enabled{true};
bool m_is_editing_existing{false};
};
#endif // CLRSYNC_GUI_TEMPLATE_EDITOR_HPP

137
src/gui/ui_manager.cpp Normal file
View File

@@ -0,0 +1,137 @@
#include "gui/ui_manager.hpp"
#include "gui/backend/backend.hpp"
#include "gui/platform/font_loader.hpp"
#include "gui/platform/file_browser.hpp"
#include "core/config/config.hpp"
#include <imgui.h>
namespace clrsync::gui
{
ui_manager::ui_manager(backend::backend_interface* backend)
: m_backend(backend)
{
m_font_loader = new font_loader();
}
ui_manager::~ui_manager()
{
shutdown();
delete m_font_loader;
m_font_loader = nullptr;
}
bool ui_manager::initialize(const ui_config& config)
{
IMGUI_CHECKVERSION();
m_imgui_context = ImGui::CreateContext();
if (!m_imgui_context)
{
return false;
}
ImGuiIO& io = ImGui::GetIO();
if (config.enable_docking)
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
if (config.enable_keyboard_nav)
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
if (!config.ini_path.empty())
io.IniFilename = config.ini_path.c_str();
ImGui::StyleColorsDark();
if (!m_backend->init_imgui_backend())
{
ImGui::DestroyContext(static_cast<ImGuiContext*>(m_imgui_context));
m_imgui_context = nullptr;
return false;
}
ImFont *font = m_font_loader->load_font(
clrsync::core::config::instance().font().c_str(),
clrsync::core::config::instance().font_size());
if (font)
io.FontDefault = font;
return true;
}
void ui_manager::shutdown()
{
if (m_imgui_context)
{
m_backend->shutdown_imgui_backend();
ImGui::DestroyContext(static_cast<ImGuiContext*>(m_imgui_context));
m_imgui_context = nullptr;
}
}
void ui_manager::begin_frame()
{
m_backend->imgui_new_frame();
ImGui::NewFrame();
}
void ui_manager::end_frame()
{
ImGui::Render();
m_backend->imgui_render_draw_data(ImGui::GetDrawData());
}
void ui_manager::push_default_font()
{
if (m_font_loader)
m_font_loader->push_default_font();
}
void ui_manager::pop_font()
{
if (m_font_loader)
m_font_loader->pop_font();
}
std::vector<std::string> ui_manager::get_system_fonts() const
{
if (m_font_loader)
return m_font_loader->get_system_fonts();
return {};
}
bool ui_manager::reload_font(const char* font_name, float size)
{
if (!m_font_loader)
return false;
ImFont* font = m_font_loader->load_font(font_name, size);
if (font)
{
ImGui::GetIO().FontDefault = font;
return true;
}
return false;
}
std::string ui_manager::open_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters)
{
return file_dialogs::open_file_dialog(title, initial_path, filters);
}
std::string ui_manager::save_file_dialog(const std::string& title,
const std::string& initial_path,
const std::vector<std::string>& filters)
{
return file_dialogs::save_file_dialog(title, initial_path, filters);
}
std::string ui_manager::select_folder_dialog(const std::string& title,
const std::string& initial_path)
{
return file_dialogs::select_folder_dialog(title, initial_path);
}
}

58
src/gui/ui_manager.hpp Normal file
View File

@@ -0,0 +1,58 @@
#ifndef CLRSYNC_UI_MANAGER_HPP
#define CLRSYNC_UI_MANAGER_HPP
#include <string>
#include <vector>
class font_loader;
struct ImFont;
namespace clrsync::gui::backend
{
class backend_interface;
}
namespace clrsync::gui
{
struct ui_config
{
std::string ini_path = "";
bool enable_docking = true;
bool enable_keyboard_nav = true;
};
class ui_manager
{
public:
explicit ui_manager(backend::backend_interface *backend);
~ui_manager();
bool initialize(const ui_config& config = ui_config());
void shutdown();
void begin_frame();
void end_frame();
void push_default_font();
void pop_font();
std::vector<std::string> get_system_fonts() const;
bool reload_font(const char* font_name, float size);
std::string open_file_dialog(const std::string& title = "Open File",
const std::string& initial_path = "",
const std::vector<std::string>& filters = {});
std::string save_file_dialog(const std::string& title = "Save File",
const std::string& initial_path = "",
const std::vector<std::string>& filters = {});
std::string select_folder_dialog(const std::string& title = "Select Folder",
const std::string& initial_path = "");
private:
backend::backend_interface *m_backend;
void *m_imgui_context = nullptr;
font_loader *m_font_loader = nullptr;
};
}
#endif

View File

@@ -0,0 +1,66 @@
#include "gui/views/about_window.hpp"
#include "core/common/version.hpp"
#include "gui/widgets/centered_text.hpp"
#include "gui/widgets/colors.hpp"
#include "gui/widgets/link_button.hpp"
#include "imgui.h"
about_window::about_window() = default;
void about_window::render(const clrsync::core::palette &pal)
{
if (!m_visible)
return;
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
if (ImGui::Begin("About clrsync", &m_visible, ImGuiWindowFlags_NoResize))
{
using namespace clrsync::gui::widgets;
ImVec4 title_color = palette_color(pal, "info", "accent");
centered_text("clrsync", title_color);
ImVec4 subtitle_color = palette_color(pal, "editor_inactive", "foreground");
centered_text("Version " + clrsync::core::version_string(), subtitle_color);
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::TextWrapped("A color scheme management tool.");
ImGui::Spacing();
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
constexpr float button_width = 200.0f;
float spacing = ImGui::GetStyle().ItemSpacing.x;
float total_width = 2.0f * button_width + spacing;
centered_buttons(total_width, [button_width]() {
link_button("GitHub Repository", "https://github.com/obsqrbtz/clrsync", button_width);
ImGui::SameLine();
link_button("Documentation", "https://binarygoose.dev/projects/clrsync/overview/", button_width);
});
ImGui::Spacing();
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::TextColored(subtitle_color, "MIT License");
ImGui::TextWrapped(
"Copyright (c) 2025 Daniel Dada\n\n"
"Permission is hereby granted, free of charge, to any person obtaining a copy "
"of this software and associated documentation files (the \"Software\"), to deal "
"in the Software without restriction, including without limitation the rights "
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell "
"copies of the Software, and to permit persons to whom the Software is "
"furnished to do so, subject to the following conditions:\n\n"
"The above copyright notice and this permission notice shall be included in all "
"copies or substantial portions of the Software.");
}
ImGui::End();
}

View File

@@ -0,0 +1,33 @@
#ifndef CLRSYNC_GUI_ABOUT_WINDOW_HPP
#define CLRSYNC_GUI_ABOUT_WINDOW_HPP
#include "core/palette/palette.hpp"
class about_window
{
public:
about_window();
void render(const clrsync::core::palette &pal);
void render()
{
render(m_default_palette);
}
void show()
{
m_visible = true;
}
void hide()
{
m_visible = false;
}
bool is_visible() const
{
return m_visible;
}
private:
bool m_visible{false};
clrsync::core::palette m_default_palette;
};
#endif // CLRSYNC_GUI_ABOUT_WINDOW_HPP

View File

@@ -0,0 +1,151 @@
#include "color_scheme_editor.hpp"
#include "gui/controllers/theme_applier.hpp"
#include "gui/widgets/dialogs.hpp"
#include "gui/widgets/palette_selector.hpp"
#include "gui/widgets/input_dialog.hpp"
#include "gui/widgets/action_buttons.hpp"
#include "imgui.h"
#include "settings_window.hpp"
#include "template_editor.hpp"
#include <iostream>
color_scheme_editor::color_scheme_editor()
{
const auto &current = m_controller.current_palette();
if (!current.colors().empty())
{
theme_applier::apply_to_imgui(current);
m_preview.apply_palette(current);
}
else
{
std::cout << "WARNING: No palette loaded, skipping theme application\n";
}
setup_widgets();
}
void color_scheme_editor::notify_palette_changed()
{
if (m_template_editor)
{
m_template_editor->apply_current_palette(m_controller.current_palette());
}
if (m_settings_window)
{
m_settings_window->set_palette(m_controller.current_palette());
}
}
void color_scheme_editor::apply_themes()
{
const auto &current = m_controller.current_palette();
theme_applier::apply_to_imgui(current);
m_preview.apply_palette(current);
notify_palette_changed();
}
void color_scheme_editor::render_controls_and_colors()
{
ImGui::Begin("Color Schemes");
render_controls();
ImGui::Separator();
ImGui::BeginChild("ColorTableContent", ImVec2(0, 0), false);
m_color_table.render(m_controller.current_palette(), m_controller,
[this]() { apply_themes(); });
ImGui::EndChild();
ImGui::End();
}
void color_scheme_editor::render_preview()
{
ImGui::Begin("Color Preview");
m_preview.render(m_controller.current_palette());
ImGui::End();
}
void color_scheme_editor::render_controls()
{
const auto &current = m_controller.current_palette();
const auto &palettes = m_controller.palettes();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(6, 8));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8, 5));
ImGui::AlignTextToFramePadding();
ImGui::Text("Palette:");
ImGui::SameLine();
m_palette_selector.render(m_controller, 200.0f);
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 8);
if (ImGui::Button(" + New "))
{
m_new_palette_dialog.open("New Palette", "Enter a name for the new palette:", "Palette name...");
}
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Create a new palette");
m_new_palette_dialog.render();
ImGui::SameLine();
m_action_buttons.render(current);
if (m_show_delete_confirmation)
{
ImGui::OpenPopup("Delete Palette?");
m_show_delete_confirmation = false;
}
clrsync::gui::widgets::delete_confirmation_dialog("Delete Palette?", current.name(), "palette",
current, [this]() {
m_controller.delete_current_palette();
apply_themes();
});
ImGui::PopStyleVar(2);
}
void color_scheme_editor::setup_widgets()
{
m_palette_selector.set_on_selection_changed([this](const std::string &name) {
m_controller.select_palette(name);
apply_themes();
});
m_new_palette_dialog.set_on_submit([this](const std::string &name) {
m_controller.create_palette(name);
m_controller.select_palette(name);
apply_themes();
});
m_action_buttons.add_button({
" Save ",
"Save current palette to file",
[this]() { m_controller.save_current_palette(); }
});
m_action_buttons.add_button({
" Delete ",
"Delete current palette",
[this]() { m_show_delete_confirmation = true; },
true,
true
});
m_action_buttons.add_button({
" Apply Theme ",
"Apply current palette to all enabled templates",
[this]() { m_controller.apply_current_theme(); }
});
m_action_buttons.set_spacing(16.0f);
}

View File

@@ -0,0 +1,52 @@
#ifndef CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP
#define CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP
#include "gui/controllers/palette_controller.hpp"
#include "gui/views/color_table_renderer.hpp"
#include "gui/views/preview_renderer.hpp"
#include "gui/widgets/palette_selector.hpp"
#include "gui/widgets/input_dialog.hpp"
#include "gui/widgets/action_buttons.hpp"
class template_editor;
class settings_window;
class color_scheme_editor
{
public:
color_scheme_editor();
void render_controls_and_colors();
void render_preview();
void set_template_editor(template_editor *editor)
{
m_template_editor = editor;
}
void set_settings_window(settings_window *window)
{
m_settings_window = window;
}
const palette_controller &controller() const
{
return m_controller;
}
private:
void render_controls();
void apply_themes();
void notify_palette_changed();
void setup_widgets();
palette_controller m_controller;
color_table_renderer m_color_table;
preview_renderer m_preview;
template_editor *m_template_editor{nullptr};
settings_window *m_settings_window{nullptr};
bool m_show_delete_confirmation{false};
clrsync::gui::widgets::palette_selector m_palette_selector;
clrsync::gui::widgets::input_dialog m_new_palette_dialog;
clrsync::gui::widgets::action_buttons m_action_buttons;
};
#endif // CLRSYNC_GUI_COLOR_SCHEME_EDITOR_HPP

Some files were not shown because too many files have changed in this diff Show More