-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc-panel.c
160 lines (128 loc) · 4.98 KB
/
c-panel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> // For system()
#include <sys/wait.h> // For waitpid()
#include <stdio.h> // For popen()
#include <errno.h> // For errno
#define BUTTON_WIDTH 100
#define BUTTON_HEIGHT 30
#define BUTTON_SPACING 10
void open_startmenu() {
system("build/menu");
}
// Function to get the list of open applications
char **get_open_applications() {
FILE *pipe = popen("wmctrl -l", "r");
if (pipe == NULL) {
perror("popen failed");
return NULL;
}
char *line = NULL;
size_t len = 0;
ssize_t read;
int count = 0;
char **applications = NULL;
while ((read = getline(&line, &len, pipe)) != -1) {
// Skip the first line which is a header
if (count == 0) {
count++;
continue;
}
// Extract the window title
char *title = strrchr(line, ' ');
if (title != NULL) {
// Skip certain titles
if (strstr(title, "Panel") || strstr(title, "Desktop") ||
strstr(title, "Whisker Menu") || strstr(title, "Find") ||
strstr(title, "Open") || strstr(title, "xfce4-panel")) {
continue;
}
title++; // Move to the first character of the title
// Resize the applications array
applications = realloc(applications, sizeof(char *) * (count + 1));
if (applications == NULL) {
perror("realloc failed");
free(line);
pclose(pipe);
return NULL;
}
// Duplicate the title
applications[count - 1] = strdup(title);
count++;
}
}
free(line);
pclose(pipe);
// Add a NULL terminator
applications = realloc(applications, sizeof(char *) * (count + 1));
applications[count] = NULL;
return applications;
}
int main(int argc, char *argv[]) {
gtk_init(&argc, &argv);
// Create a GtkWindow with no decorations
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
// Set window size
gtk_window_set_default_size(GTK_WINDOW(window), 100, 50);
// Make the window the same width as the display
GdkScreen *screen = gdk_screen_get_default();
int width = gdk_screen_get_width(screen);
int height = gdk_screen_get_height(screen);
gtk_window_resize(GTK_WINDOW(window), width, 50);
// Move window to bottom of the screen
gtk_window_move(GTK_WINDOW(window), 0, height - 50);
// Create a GtkFixed container to hold the image
GtkWidget *fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), fixed);
// Set taskbar image
GtkWidget *image1 = gtk_image_new_from_file("/home/anon/.comfy/panel.png");
gtk_fixed_put(GTK_FIXED(fixed), image1, 0, 0);
// Create the start menu button
GtkWidget *startmenu_button = gtk_button_new();
GtkWidget *image2 = gtk_image_new_from_file("assets/clover.png");
gtk_button_set_image(GTK_BUTTON(startmenu_button), image2);
gtk_fixed_put(GTK_FIXED(fixed), startmenu_button, 5, 0); // Move to the leftmost position
g_signal_connect(startmenu_button, "clicked", G_CALLBACK(open_startmenu), NULL);
// Get the list of open applications
char **open_apps = get_open_applications();
if (open_apps == NULL) {
// Handle the error
gtk_main();
return 1;
}
// Add open application buttons (dynamically)
int x_offset = 75; // Start position for application buttons
for (int i = 0; open_apps[i] != NULL; i++) {
// Get the application name
char *app_name = open_apps[i];
// Create a button with the application name
GtkWidget *app_button = gtk_button_new_with_label(app_name);
// Set the application name as the button's tooltip
gtk_widget_set_tooltip_text(app_button, app_name);
// Set button width
gtk_widget_set_size_request(app_button, BUTTON_WIDTH, BUTTON_HEIGHT);
// Position the button
gtk_fixed_put(GTK_FIXED(fixed), app_button, x_offset, 0);
x_offset += BUTTON_WIDTH + BUTTON_SPACING; // Adjust x_offset for next button
}
// Free allocated memory for open_apps
for (int i = 0; open_apps[i] != NULL; i++) {
free(open_apps[i]);
}
free(open_apps);
// Set the window as a top-level window (always on top)
gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DOCK);
// Show the window
gtk_widget_show_all(window);
// Load CSS style
GtkCssProvider *provider = gtk_css_provider_new();
gtk_css_provider_load_from_file(provider, g_file_new_for_path("style.css"), NULL);
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
// Set the application name for the taskbar
gtk_window_set_title(GTK_WINDOW(window), "Panel");
gtk_main();
return 0;
}