Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
86c43720cb | |||
9c639978d0 | |||
23c3d1aebf | |||
871c268bc3 | |||
fcdabcb59d | |||
1cba6e01e7 | |||
911060ecf7 | |||
8b3bde4c5a |
13
README.md
13
README.md
@ -6,25 +6,28 @@ A simple Shutdown Dialog for Openbox written in C using GTK
|
||||
|
||||
## Why?
|
||||
|
||||
I just bought a new laptop and on my workstation I was using [ssd from Sawfish](https://github.com/SawfishWM/ssd) which I loved. I didn't want to go through all the steps of installing the necessary libraries and dependencies to get it to work, so I decided to create my own.
|
||||
Been using Openbox many many years and loving it. One of the main issue I have with it is its incredibly simple Exit dialog. On a modern system, a better solution is needed.
|
||||
I guess there are many programs such as this one out there, but one more doesn't hurt, does it?
|
||||
|
||||
Anyway, I just bought a new laptop and on my workstation I was using [ssd from Sawfish](https://github.com/SawfishWM/ssd) which I loved. I didn't want to go through all the steps of installing the necessary libraries and dependencies to get it to work, so I decided to create my own.
|
||||
|
||||
## Dependencies and compilation
|
||||
|
||||
This app requires GTK+ 3.0 development libraries and gcc or clang.
|
||||
This app requires GTK+ 3.0, Glib 2 development libraries and gcc or clang.
|
||||
|
||||
I am using this command to compile the program:
|
||||
|
||||
Using GCC:
|
||||
```shell
|
||||
% gcc ssdd.c -o ssdd `pkg-config --cflags --libs gtk+-3.0`
|
||||
% gcc ssdd.c resources.c -o ssdd `pkg-config --cflags --libs gtk+-3.0`
|
||||
```
|
||||
|
||||
Using Clang:
|
||||
```shell
|
||||
% clang ssdd.c -o ssdd `pkg-config --cflags --libs gtk+-3.0`
|
||||
% clang ssdd.c resources.c -o ssdd `pkg-config --cflags --libs gtk+-3.0`
|
||||
```
|
||||
|
||||
This produces the binary `ssdd` which you can place in your $PATH.
|
||||
This produces the binary `ssdd` which you can place in your $PATH. I place mine in `~/bin`. You can strip if, but it'll only save you a few kilobytes, so it's basically unnecessary...
|
||||
|
||||
## Configure Openbox to use it.
|
||||
|
||||
|
3844
resources.c
Normal file
3844
resources.c
Normal file
File diff suppressed because it is too large
Load Diff
7
resources.gresource.xml
Normal file
7
resources.gresource.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/org/gtk/example">
|
||||
<file>ssdd-icon.png</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
7
resources.h
Normal file
7
resources.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef __RESOURCE_resources_H__
|
||||
#define __RESOURCE_resources_H__
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
extern GResource *resources_get_resource (void);
|
||||
#endif
|
BIN
ssdd-icon.png
BIN
ssdd-icon.png
Binary file not shown.
Before Width: | Height: | Size: 176 KiB After Width: | Height: | Size: 57 KiB |
76
ssdd.c
76
ssdd.c
@ -1,5 +1,6 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
#include "resources.h" // Include the generated resource header
|
||||
|
||||
static void execute_command(const gchar *command) {
|
||||
int ret = system(command);
|
||||
@ -47,11 +48,11 @@ static void show_about_dialog(GtkWidget *widget) {
|
||||
GtkWidget *image;
|
||||
GtkWidget *box;
|
||||
const gchar *about_text =
|
||||
"About Stig's ShutDown Dialog\n\n"
|
||||
"<b>Version:</b> 1.0\n"
|
||||
"\n<b>About Stig's ShutDown Dialog</b>\n\n"
|
||||
"<b>Version:</b> 1.2\n"
|
||||
"<b>Author:</b> kekePower\n"
|
||||
"<b>URL:</b> <a href=\"https://git.kekepower.com/kekePower/ssdd\">https://git.kekepower.com/kekePower/ssdd</a>\n"
|
||||
"<b>Description:</b> This is a simple Shutdown Dialog for Openbox.";
|
||||
"<b>Description:</b> This is a simple Shutdown Dialog for Openbox.\n";
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons("About Stig's ShutDown Dialog",
|
||||
NULL,
|
||||
@ -63,7 +64,7 @@ static void show_about_dialog(GtkWidget *widget) {
|
||||
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
|
||||
gtk_container_add(GTK_CONTAINER(content_area), box);
|
||||
|
||||
image = gtk_image_new_from_file("ssdd-icon.png");
|
||||
image = gtk_image_new_from_resource("/org/gtk/example/ssdd-icon.png");
|
||||
gtk_image_set_pixel_size(GTK_IMAGE(image), 250); // Assuming original size is 500x500
|
||||
gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
|
||||
|
||||
@ -96,20 +97,45 @@ static void button_clicked(GtkWidget *widget, gpointer data) {
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) {
|
||||
if (event->keyval == GDK_KEY_Escape) {
|
||||
g_application_quit(G_APPLICATION(data));
|
||||
return TRUE; // Event handled
|
||||
}
|
||||
return FALSE; // Event not handled
|
||||
}
|
||||
|
||||
static void create_button(GtkWidget *grid, GtkApplication *app, const gchar *label_text, const gchar *icon_name, const gchar *command, int pos) {
|
||||
GtkWidget *button;
|
||||
GtkWidget *box;
|
||||
GtkWidget *image;
|
||||
GtkWidget *label;
|
||||
|
||||
button = gtk_button_new();
|
||||
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
|
||||
gtk_container_add(GTK_CONTAINER(button), box);
|
||||
|
||||
image = gtk_image_new_from_icon_name(icon_name, GTK_ICON_SIZE_BUTTON);
|
||||
gtk_box_pack_start(GTK_BOX(box), image, TRUE, TRUE, 0);
|
||||
|
||||
label = gtk_label_new(label_text);
|
||||
gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
|
||||
|
||||
g_object_set_data(G_OBJECT(button), "app", app);
|
||||
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), (gpointer) command);
|
||||
gtk_grid_attach(GTK_GRID(grid), button, pos % 4, pos / 4, 1, 1);
|
||||
}
|
||||
|
||||
static void activate(GtkApplication *app, gpointer user_data) {
|
||||
GtkWidget *window;
|
||||
GtkWidget *grid;
|
||||
GtkWidget *button;
|
||||
GtkWidget *image;
|
||||
GtkWidget *box;
|
||||
GtkWidget *label;
|
||||
const gchar *buttons[] = {
|
||||
"openbox --exit",
|
||||
"dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Reboot boolean:true",
|
||||
"dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.PowerOff boolean:true",
|
||||
"systemctl reboot",
|
||||
"systemctl poweroff",
|
||||
"dm-tool switch-to-greeter",
|
||||
"dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Suspend boolean:true",
|
||||
"dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Hibernate boolean:true",
|
||||
"systemctl suspend",
|
||||
"systemctl hibernate",
|
||||
"about",
|
||||
"exit"
|
||||
};
|
||||
@ -138,27 +164,18 @@ static void activate(GtkApplication *app, gpointer user_data) {
|
||||
gtk_window_set_title(GTK_WINDOW(window), "Exit Openbox");
|
||||
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
|
||||
|
||||
gtk_window_set_icon_from_file(GTK_WINDOW(window), "ssdd-icon.png", NULL);
|
||||
// Load the icon from the resource and set it as the window icon
|
||||
GdkPixbuf *icon_pixbuf = gdk_pixbuf_new_from_resource("/org/gtk/example/ssdd-icon.png", NULL);
|
||||
gtk_window_set_icon(GTK_WINDOW(window), icon_pixbuf);
|
||||
g_object_unref(icon_pixbuf); // Free the icon pixbuf after setting it
|
||||
|
||||
g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), app);
|
||||
|
||||
grid = gtk_grid_new();
|
||||
gtk_container_add(GTK_CONTAINER(window), grid);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
button = gtk_button_new();
|
||||
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
|
||||
gtk_container_add(GTK_CONTAINER(button), box);
|
||||
|
||||
image = gtk_image_new_from_icon_name(icons[i], GTK_ICON_SIZE_BUTTON);
|
||||
gtk_box_pack_start(GTK_BOX(box), image, TRUE, TRUE, 0);
|
||||
|
||||
label = gtk_label_new(labels[i]);
|
||||
gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
|
||||
|
||||
gtk_button_set_label(GTK_BUTTON(button), labels[i]);
|
||||
|
||||
g_object_set_data(G_OBJECT(button), "app", app);
|
||||
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), (gpointer) buttons[i]);
|
||||
gtk_grid_attach(GTK_GRID(grid), button, i % 4, i / 4, 1, 1);
|
||||
create_button(grid, app, labels[i], icons[i], buttons[i], i);
|
||||
}
|
||||
|
||||
gtk_widget_show_all(window);
|
||||
@ -168,6 +185,9 @@ int main(int argc, char **argv) {
|
||||
GtkApplication *app;
|
||||
int status;
|
||||
|
||||
// Register the resource
|
||||
g_resources_register(resources_get_resource());
|
||||
|
||||
app = gtk_application_new("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
|
||||
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
|
||||
status = g_application_run(G_APPLICATION(app), argc, argv);
|
||||
|
Reference in New Issue
Block a user