Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Add pywal support
Browse files Browse the repository at this point in the history
Add css to config
Fixes #10
  • Loading branch information
wvffle committed Jan 8, 2020
1 parent 3996030 commit 7253357
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})
#add_definitions(${WAYLAND_DEFINITIONS})

add_executable(waffy src/main.c src/utils.h src/utils.c src/find_desktop.c src/find_desktop.h src/desktop_entry.c src/desktop_entry.h src/filter.c src/filter.h src/config.c src/config.h)
add_executable(waffy src/main.c src/utils.h src/utils.c src/find_desktop.c src/find_desktop.h src/desktop_entry.c src/desktop_entry.h src/filter.c src/filter.h src/config.c src/config.h src/colors.c src/colors.h)
target_link_libraries(waffy ${GTK3_LAYER_SHELL_LIBRARIES} ${WAYLAND_LIBRARIES} ${GTK3_LIBRARIES})
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Wayland compatible, touch friendly application launcher
- Fuzzy find apps

## Requirements
- [gtk-layer-shell](https://github.com/wmww/gtk-layer-shell/) - A library to write GTK applications that use Layer Shell
- [gtk-layer-shell](https://github.com/wmww/gtk-layer-shell) - A library to write GTK applications that use Layer Shell

## Other information
- [Studies project info](/docs/project.md)
29 changes: 24 additions & 5 deletions assets/main.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
window {
background: rgba(0, 0, 0, .7);
}

label {
color: #fff;
Expand Down Expand Up @@ -28,11 +25,33 @@ textview text {
}

#apps > button {
background: rgba(255, 255, 255, .1);
min-width: 270px;
transition: none;
border: none;
}

/* default colors */
window {
background: alpha(#000, .7);
}

#apps > button {
background: alpha(#fff, .1);
}

#apps > button.active {
background: rgba(255, 255, 255, .3);
background: alpha(#fff, .3);
}

/* pywal colors */
window.pywal {
background: alpha(@background, .7);
}

window.pywal #apps > button {
background: @background;
}

window.pywal #apps > button.active {
background: @color5;
}
5 changes: 3 additions & 2 deletions docs/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ Year | 2019 / 2020
Everything is inside the `*.h` files

- [Structures example](/src/desktop_entry.h#L14)
- [File operation example](/src/config.c#L10)
- [File operation example](/src/config.c#L18)
- [List example](/src/desktop_entry.h#L28)
- [Functions example](/src/utils.c#L32)
- [Function example](/src/utils.c#L36)
- [Recursive function example](/src/config.c#L59)

### Open source
Well it turned out that I've found a bug in sway which is my main wayland client
Expand Down
27 changes: 27 additions & 0 deletions src/colors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Created by waff on 1/8/20.
//

#include "colors.h"
#include "config.h"

char* get_css () {
open_config();

char* css_file = str_concat(get_user_home(), "/.config/waffy/main.css");

FILE* fp = fopen(css_file, "r");
if (fp == NULL) {
fp = fopen(css_file, "w");
fprintf(fp, "%s", read_file("../assets/main.css"));
}

fclose(fp);

if (config_wal == 1) {
char* wal_file = str_concat(get_user_home(), "/.cache/wal/colors-waybar.css");
return str_concat(read_file(wal_file), read_file(css_file));
}

return read_file(css_file);
}
12 changes: 12 additions & 0 deletions src/colors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by waff on 1/8/20.
//

#ifndef WAFFY_COLORS_H
#define WAFFY_COLORS_H

#include "utils.h"

char* get_css ();

#endif //WAFFY_COLORS_H
12 changes: 7 additions & 5 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "config.h"

char* config_dir = NULL;

// Default config
long config_columns = 4;
long config_wal = 0;
Expand All @@ -14,6 +16,10 @@ void get_str(char *value, char** res);
void get_bool(char* value, long* res);

void open_config() {
if (config_dir != NULL) return;
config_dir = str_concat(get_user_home(), "/.config/waffy");
mkdir(config_dir, 0755);

char* file = str_concat(get_user_home(), "/.config/waffy/config");
FILE* fp = fopen(file, "r");

Expand Down Expand Up @@ -84,11 +90,7 @@ void get_long(char *value, long *res) {
}

void write_config() {
char* dir = str_concat(get_user_home(), "/.config/waffy");
char* file = str_concat(dir, "/config");

mkdir(dir, 0755);

char* file = str_concat(config_dir, "/config");
FILE* fp = fopen(file, "w");

fprintf(fp, "columns %ld\n", config_columns);
Expand Down
1 change: 0 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define MAX_CONFIG_LINE_LENGTH 256

#include <stdio.h>
#include <sys/stat.h>
#include "utils.h"

long config_columns;
Expand Down
10 changes: 7 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "find_desktop.h"
#include "filter.h"
#include "config.h"
#include "colors.h"

#define ICON_SIZE 48
#define MAX_CHARS 16
Expand Down Expand Up @@ -358,11 +359,14 @@ int main (int argc, char* argv[]) {

update_apps(all_desktop_entries);

// Set window style
// TODO: Respect pywal
GtkCssProvider* css_provider = gtk_css_provider_new();

if (gtk_css_provider_load_from_path(css_provider, "../assets/main.css", NULL)) {
if (config_wal == 1) {
add_class(window, "pywal");
}

char* css = get_css();
if (gtk_css_provider_load_from_data(css_provider, css, strlen(css), NULL)) {
gtk_style_context_add_provider_for_screen(gtk_widget_get_screen(window),
GTK_STYLE_PROVIDER(css_provider),
GTK_STYLE_PROVIDER_PRIORITY_USER);
Expand Down
13 changes: 13 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

#include "utils.h"

char *read_file(const char *path) {
FILE* fp = fopen(path, "r");
if (fp == NULL) return "";

size_t len;
char* res = NULL;
ssize_t bytes_read = getdelim(&res, &len, '\0', fp);
fclose(fp);

if (bytes_read == -1) return "";
return res;
}

int str_starts_with (const char *hay, const char *needle) {
return strncmp(needle, hay, strlen(needle)) == 0;
}
Expand Down
5 changes: 5 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>

// Read whole file into a string
char* read_file (const char* path);

// Removes whitespaces from start and end of string
char* str_trim (const char* str);
Expand Down

0 comments on commit 7253357

Please sign in to comment.