new-dialogue #8
							
								
								
									
										66
									
								
								src/gui/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								src/gui/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
				
			|||||||
 | 
					SHELL=/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# configurable options
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SOURCES_DIR := .
 | 
				
			||||||
 | 
					TESTS_DIR := .
 | 
				
			||||||
 | 
					BUILD_DIR := .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CC := gcc
 | 
				
			||||||
 | 
					CXX := g++
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# dependencies
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PACKAGE_NAMES := gtk4 libadwaita-1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ifeq ($(TEST), 1)
 | 
				
			||||||
 | 
						#	PACKAGE_NAMES += check # TODO: use check?
 | 
				
			||||||
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# set up cflags and libs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CFLAGS := -D_FILE_OFFSET_BITS=64
 | 
				
			||||||
 | 
					LDFLAGS :=
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CFLAGS += $(shell pkg-config --cflags $(PACKAGE_NAMES))
 | 
				
			||||||
 | 
					LDFLAGS += $(shell pkg-config --libs $(PACKAGE_NAMES))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ifeq ($(DEBUG),1)
 | 
				
			||||||
 | 
						CFLAGS += -O0 -pedantic -g -Wall -Wextra -Wcast-align \
 | 
				
			||||||
 | 
											-Wcast-qual -Wdisabled-optimization -Wformat=2 \
 | 
				
			||||||
 | 
											-Winit-self -Wlogical-op -Wmissing-declarations \
 | 
				
			||||||
 | 
											-Wmissing-include-dirs -Wredundant-decls -Wshadow \
 | 
				
			||||||
 | 
											-Wsign-conversion -Wstrict-overflow=5 \
 | 
				
			||||||
 | 
											-Wswitch-default -Wundef -Wno-unused
 | 
				
			||||||
 | 
						LDFLAGS += 
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
						CFLAGS += -O3
 | 
				
			||||||
 | 
						LDFLAGS +=
 | 
				
			||||||
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# set up targets 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TARGETS := $(BUILD_DIR)/zenity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ifeq ($(TEST), 1)
 | 
				
			||||||
 | 
						#TARGETS += icfs_test
 | 
				
			||||||
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# build!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					default: $(TARGETS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: clean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(BUILD_DIR)/zenity: $(BUILD_DIR)/zenity.o
 | 
				
			||||||
 | 
						$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $(BUILD_DIR)/zenity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(BUILD_DIR)/zenity.o: $(SOURCES_DIR)/zenity-clone.c
 | 
				
			||||||
 | 
						$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $(BUILD_DIR)/zenity.o
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					clean:
 | 
				
			||||||
 | 
						rm $(BUILD_DIR)/*.o $(BUILD_DIR)/zenity
 | 
				
			||||||
							
								
								
									
										41
									
								
								src/gui/zenity-clone.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/gui/zenity-clone.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					#include "gio/gio.h"
 | 
				
			||||||
 | 
					#include <adwaita.h>
 | 
				
			||||||
 | 
					#include <gtk/gtk.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void on_activate(GtkApplication *app, gpointer user_data) {
 | 
				
			||||||
 | 
					  // Create the main window
 | 
				
			||||||
 | 
					  AdwMessageDialog *dialog = ADW_MESSAGE_DIALOG(
 | 
				
			||||||
 | 
					      adw_message_dialog_new(NULL, "Allow access?", "allow_access?"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Set the dialog as transient for the (non-existent) parent window
 | 
				
			||||||
 | 
					  gtk_window_set_application(GTK_WINDOW(dialog), app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Add response buttons
 | 
				
			||||||
 | 
					  adw_message_dialog_add_response(dialog, "cancel", "Cancel");
 | 
				
			||||||
 | 
					  adw_message_dialog_add_response(dialog, "ok", "OK");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Set default response
 | 
				
			||||||
 | 
					  adw_message_dialog_set_default_response(dialog, "ok");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Set close response (when clicking X)
 | 
				
			||||||
 | 
					  adw_message_dialog_set_close_response(dialog, "cancel");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Connect response handler
 | 
				
			||||||
 | 
					  // g_signal_connect(dialog, "response", G_CALLBACK(gtk_window_close), dialog);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Show the dialog
 | 
				
			||||||
 | 
					  gtk_window_present(GTK_WINDOW(dialog));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char **argv) {
 | 
				
			||||||
 | 
					  // Create a new application
 | 
				
			||||||
 | 
					  AdwApplication *app = adw_application_new("com.example.zenityclone",
 | 
				
			||||||
 | 
					                                            G_APPLICATION_DEFAULT_FLAGS);
 | 
				
			||||||
 | 
					  g_signal_connect(app, "activate", G_CALLBACK(on_activate), NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Run the application
 | 
				
			||||||
 | 
					  int status = g_application_run(G_APPLICATION(app), argc, argv);
 | 
				
			||||||
 | 
					  g_object_unref(app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return status;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user