23 Commits
v1.1 ... v1.4

Author SHA1 Message Date
8ae0b72624 Update to version 1.4. Place the buttons together and give them a bit of air. This looks, imho, a lot better. 2024-07-28 01:09:48 +02:00
65946c76fc Update to version 1.3
- Added `resources.c` and `resources.h` to the `.gitignore` file.
- Modified the `execute_command` function to use `g_spawn_command_line_async` for asynchronous command execution.
- Updated the `show_confirmation_dialog` function to display a GTK dialog with a warning icon and improved layout.
- Added a margin to the buttons in the `create_button` function for better spacing.
- Improved error handling for loading the window icon in the `activate` function.
- Updated README.md with more information about manually compiling ssdd
2024-07-12 08:08:54 +02:00
152a0d648c Update screenshot 2024-07-12 00:41:05 +02:00
40f35759b9 Update after rebuild of resources 2024-07-12 00:39:32 +02:00
2a53ed3845 Rename to Simple ShutDown Dialog again 2024-07-12 00:37:57 +02:00
8edde79fa0 Rename to Simple ShutDown Dialog 2024-07-12 00:35:34 +02:00
19c42e9a52 Update README.md with better and more concise information about the project 2024-07-11 23:29:09 +02:00
7e9b159204 Remove test1234 2024-07-05 12:29:16 +02:00
872159b8ab A test commit1234 2024-07-05 12:28:33 +02:00
875c768cea Remove test123 2024-07-05 12:26:36 +02:00
9e08851964 A test commit 2024-07-05 12:18:23 +02:00
3a16bc04d5 Remove test 2024-07-05 12:14:39 +02:00
76ae1590f6 A test commit 2024-07-05 12:14:09 +02:00
20113cc0c9 Remove test 2024-07-05 12:04:34 +02:00
0e92c38db0 A test commit 2024-07-05 12:02:17 +02:00
9d98d6056f README.md: Updated info about Makefile 2024-07-05 11:55:09 +02:00
a54cac53f2 Added Makefile 2024-07-05 10:55:35 +02:00
2d10e570be Fixed typo in README.md 2024-07-05 10:35:48 +02:00
ef25b54a22 Rename app from example to ssdd 2024-07-04 08:11:08 +02:00
86c43720cb Update to version 1.2 2024-07-01 23:02:08 +02:00
9c639978d0 Reduced size of About image and hence reduced the size of the binary from 199kb to 79kb 2024-07-01 22:34:48 +02:00
23c3d1aebf Add question to all 6 actions 2024-07-01 22:29:12 +02:00
871c268bc3 Update README.me 2024-06-30 12:57:34 +02:00
9 changed files with 238 additions and 11536 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
ssdd
resources.c
resources.h

52
Makefile Normal file
View File

@ -0,0 +1,52 @@
# Compiler
CC = gcc
# Compiler and optimization flags
CFLAGS = `pkg-config --cflags gtk+-3.0` -O3
LDFLAGS = `pkg-config --libs gtk+-3.0`
# Source files
SRC = ssdd.c resources.c
# Output executable
TARGET = ssdd
# Resource files
RESOURCE_XML = resources.gresource.xml
RESOURCE_C = resources.c
RESOURCE_H = resources.h
# Installation directories
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
DATADIR = $(PREFIX)/share/ssdd
# Default target
all: $(TARGET)
# Build the target
$(TARGET): $(RESOURCE_C) $(SRC)
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
# Compile resources
$(RESOURCE_C) $(RESOURCE_H): $(RESOURCE_XML)
glib-compile-resources $(RESOURCE_XML) --generate-source --target=$(RESOURCE_C)
glib-compile-resources $(RESOURCE_XML) --generate-header --target=$(RESOURCE_H)
# Install target
install: $(TARGET)
install -d $(BINDIR)
install -m 755 $(TARGET) $(BINDIR)
install -d $(DATADIR)
install -m 644 $(RESOURCE_XML) $(DATADIR)
# Uninstall target
uninstall:
rm -f $(BINDIR)/$(TARGET)
rm -rf $(DATADIR)
# Clean target
clean:
rm -f $(TARGET) $(RESOURCE_C) $(RESOURCE_H)
.PHONY: all clean install uninstall

View File

@ -1,39 +1,79 @@
# ssdd
# ssdd: Simple Shutdown Dialog for Openbox
A simple Shutdown Dialog for Openbox written in C using GTK
![Project Screenshot](ssdd.png)
## Why?
**Simple Shutdown Dialog (ssdd)** is a simple yet stylish shutdown dialog for Openbox, crafted in C using GTK.
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.
## Why ssdd?
## Dependencies and compilation
As a long-time Openbox enthusiast, I've always found the default exit dialog a bit lackluster. Modern systems deserve a more refined shutdown experience. While there are other options out there, I figured one more wouldn't hurt, right?
This app requires GTK+ 3.0 development libraries and gcc or clang.
Inspired by the elegant `ssd` from Sawfish, I decided to create my own tailored solution for Openbox. This way, you can avoid the hassle of installing extra dependencies and enjoy a sleek shutdown dialog that complements your Openbox setup.
I am using this command to compile the program:
## Features
* **Clean and Intuitive Interface:** ssdd presents a clear choice between Shutdown, Reboot, Logout, and Exit options.
* **Clean and minimal code:** `ssdd` is built on a clean and minimal codebase, making it easy to maintain, understand, and extend.
* **Lightweight and Efficient:** ssdd is designed to be fast and resource-friendly, perfectly suited for Openbox's minimalist philosophy.
## Dependencies and Compilation
ssdd requires:
* GTK+ 3.0
* Glib 2 development libraries
* gcc or clang
### Easy Compilation
Edit the `Makefile` or use the following commands:
Using GCC:
```shell
% gcc ssdd.c resources.c -o ssdd `pkg-config --cflags --libs gtk+-3.0`
% make all # Compile
% sudo make install # Install to /usr/local
```
Using Clang:
```shell
### Manual compilation
First generate the resources.
```bash
% glib-compile-resources resources.gresource.xml --generate-source --target=resources.c
% glib-compile-resources resources.gresource.xml --generate-header --target=resources.h
```
```bash
# Using GCC:
% gcc ssdd.c resources.c -o ssdd `pkg-config --cflags --libs gtk+-3.0`
# Using Clang:
% 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.
Place the `ssdd` binary in your `$PATH` (e.g., `~/bin`).
## Configure Openbox to use it.
### Integrate with Openbox
`% sudo nvim /etc/xdg/openbox/menu.xml`
1. Edit your Openbox menu:
Find the line with the standard Openbox Exit option and change it to
```bash
% sudo nvim /etc/xdg/openbox/menu.xml
```
`<item label="Log Out"><action name="Execute"><execute>ssdd</execute></item>`
2. Replace the default Exit entry with:
The reconfigure Openbox to use the new setting.
```xml
<item label="Log Out"><action name="Execute"><execute>ssdd</execute></action></item>
```
`% openbox --reconfigure`
3. Reconfigure Openbox:
```bash
% openbox --reconfigure
```
### Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.

11439
resources.c

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gtk/example">
<gresource prefix="/org/gtk/ssdd">
<file>ssdd-icon.png</file>
</gresource>
</gresources>

View File

@ -1,7 +0,0 @@
#ifndef __RESOURCE_resources_H__
#define __RESOURCE_resources_H__
#include <gio/gio.h>
extern GResource *resources_get_resource (void);
#endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 176 KiB

After

Width:  |  Height:  |  Size: 57 KiB

176
ssdd.c
View File

@ -1,41 +1,30 @@
#include <gtk/gtk.h>
#include <stdlib.h>
#include "resources.h" // Include the generated resource header
#include <glib.h>
#include "resources.h"
// Function declarations (prototypes)
static void execute_command(const gchar *command);
static void show_about_dialog(GtkWidget *widget);
static void button_clicked(GtkWidget *widget, gpointer data);
static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data);
static void show_confirmation_dialog(GtkWidget *widget, const gchar *label, const gchar *command);
static void create_button(GtkWidget *grid, GtkApplication *app, const gchar *label_text, const gchar *icon_name, const gchar *command, int pos);
static void execute_command(const gchar *command) {
int ret = system(command);
if (ret != 0) {
GError *error = NULL;
gboolean ret = g_spawn_command_line_async(command, &error);
if (!ret) {
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error executing command: %s",
command);
"Error executing command: %s\n%s",
command,
error->message);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
}
static void show_confirmation_dialog(GtkWidget *widget, gpointer data) {
const gchar *command = (const gchar *) data;
GtkWidget *dialog;
gint response;
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"Are you sure you want to execute: %s?",
command);
gtk_dialog_add_button(GTK_DIALOG(dialog), "Yes", GTK_RESPONSE_YES);
gtk_dialog_add_button(GTK_DIALOG(dialog), "No", GTK_RESPONSE_NO);
response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
if (response == GTK_RESPONSE_YES) {
execute_command(command);
g_error_free(error);
}
}
@ -46,23 +35,23 @@ static void show_about_dialog(GtkWidget *widget) {
GtkWidget *image;
GtkWidget *box;
const gchar *about_text =
"\nAbout Stig's ShutDown Dialog\n\n"
"<b>Version:</b> 1.1\n"
"\n<b>About Simple ShutDown Dialog</b>\n\n"
"<b>Version:</b> 1.4\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.\n";
dialog = gtk_dialog_new_with_buttons("About Stig's ShutDown Dialog",
dialog = gtk_dialog_new_with_buttons("About Simple ShutDown Dialog",
NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
"_Close",
GTK_RESPONSE_CLOSE,
NULL);
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(content_area), box);
image = gtk_image_new_from_resource("/org/gtk/example/ssdd-icon.png");
image = gtk_image_new_from_resource("/org/gtk/ssdd/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);
@ -81,19 +70,18 @@ static void show_about_dialog(GtkWidget *widget) {
static void button_clicked(GtkWidget *widget, gpointer data) {
const gchar *command = (const gchar *)data;
const gchar *label = g_object_get_data(G_OBJECT(widget), "label");
if (g_strcmp0(command, "exit") == 0) {
g_application_quit(G_APPLICATION(g_object_get_data(G_OBJECT(widget), "app")));
return;
}
if (g_strcmp0(command, "openbox --exit") == 0 ||
g_strcmp0(command, "systemctl reboot") == 0 ||
g_strcmp0(command, "systemctl poweroff") == 0) {
show_confirmation_dialog(widget, (gpointer) command);
} else if (g_strcmp0(command, "about") == 0) {
if (g_strcmp0(command, "about") == 0) {
show_about_dialog(widget);
} else {
execute_command(command);
GtkWidget *window = gtk_widget_get_toplevel(widget);
show_confirmation_dialog(window, label, command);
}
}
@ -105,13 +93,82 @@ static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer dat
return FALSE; // Event not handled
}
static void show_confirmation_dialog(GtkWidget *parent_window, const gchar *label, const gchar *command) {
GtkWidget *dialog;
gint response;
gchar *message = g_strdup_printf("Are you sure you want to %s?", label);
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog), "Confirmation");
// Set the transient parent correctly
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent_window));
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
gtk_container_add(GTK_CONTAINER(content_area), box);
GtkWidget *image = gtk_image_new_from_icon_name("dialog-warning", GTK_ICON_SIZE_DIALOG);
gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
GtkWidget *label_widget = gtk_label_new(message);
gtk_box_pack_start(GTK_BOX(box), label_widget, TRUE, TRUE, 0);
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
"Yes", GTK_RESPONSE_YES,
"No", GTK_RESPONSE_NO,
NULL); // Add NULL to terminate the list of buttons
GtkWidget *button_box = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); // Get content area instead of action area
gtk_box_set_spacing(GTK_BOX(button_box), 10); // Adjust spacing as needed
gtk_widget_set_margin_top(button_box, 10);
gtk_widget_show_all(dialog); // Show the dialog and its children
response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
g_free(message);
if (response == GTK_RESPONSE_YES) {
execute_command(command);
}
}
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, 10); // Set internal box spacing to 10
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);
// Set margins for the button contents
gtk_widget_set_margin_top(box, 5);
gtk_widget_set_margin_bottom(box, 5);
gtk_widget_set_margin_start(box, 5);
gtk_widget_set_margin_end(box, 5);
g_object_set_data(G_OBJECT(button), "app", app);
g_object_set_data(G_OBJECT(button), "label", (gpointer) label_text);
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",
"systemctl reboot",
@ -132,7 +189,7 @@ static void activate(GtkApplication *app, gpointer user_data) {
"help-about",
"application-exit"
};
const gchar *labels[] = {
const gchar *labels[] = { // Define the labels array here
"Logout",
"Reboot",
"Shutdown",
@ -144,32 +201,29 @@ static void activate(GtkApplication *app, gpointer user_data) {
};
window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "Exit Openbox");
gtk_window_set_title(GTK_WINDOW(window), "Simple ShutDown Dialog");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
// 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);
// Load the icon with error handling
GError *error = NULL;
GdkPixbuf *icon_pixbuf = gdk_pixbuf_new_from_resource("/org/gtk/ssdd/ssdd-icon.png", &error);
if (icon_pixbuf) {
gtk_window_set_icon(GTK_WINDOW(window), icon_pixbuf);
g_object_unref(icon_pixbuf); // Free the pixbuf
} else {
g_warning("Failed to load icon: %s", error->message);
g_error_free(error);
}
g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), app);
grid = gtk_grid_new();
gtk_grid_set_row_spacing(GTK_GRID(grid), 0); // Set the row spacing to 0
gtk_grid_set_column_spacing(GTK_GRID(grid), 0); // Set the column spacing to 0
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);
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);
@ -182,7 +236,7 @@ int main(int argc, char **argv) {
// Register the resource
g_resources_register(resources_get_resource());
app = gtk_application_new("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
app = gtk_application_new("org.gtk.ssdd", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);

BIN
ssdd.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB