|
1 | | -#include <X11/Xlib.h> |
2 | | -#include <X11/Xutil.h> |
3 | | -#include<X11/Xos.h> |
4 | | - |
5 | | -staticDisplay*display; |
6 | | -staticWindowroot; |
7 | | -staticint screen; |
8 | | -staticGCgc; |
9 | | - |
10 | | -WindowcreateWindow(intx, inty, intwidth, intheight, intborder, longborderColor, longrgb) { |
11 | | -Windowwindow=XCreateSimpleWindow(display, root, x, y, width, height, border, (long) borderColor, (long) rgb); |
12 | | - returnwindow; |
| 1 | +#include <gtk/gtk.h> |
| 2 | +#include <string.h> |
| 3 | + |
| 4 | + |
| 5 | +GtkWidget*root; |
| 6 | +GtkWidget*fixed; |
| 7 | +int window_height; |
| 8 | +intwindow_width; |
| 9 | +charwindow_title[]; |
| 10 | + |
| 11 | +voidadd_widget_to_window(GtkWidget*widget, intx, inty) { |
| 12 | + gtk_fixed_put(GTK_FIXED(fixed), widget, x, y); |
13 | 13 | }
|
14 | 14 |
|
15 | | -Window getParentWindow() { |
16 | | - return root; |
| 15 | +void add_button(char label[], int x, int y) { |
| 16 | + GtkWidget *button = gtk_button_new_with_label(label); |
| 17 | + add_widget_to_window(button, x, y); |
17 | 18 | }
|
18 | 19 |
|
19 | | -void changeWindowBackground(Window window, long background) { |
20 | | - XSetWindowBackground(display, window, background); |
| 20 | +void add_check_button(char label[], int x, int y) { |
| 21 | + GtkWidget *check_btn = gtk_check_button_new_with_label(label); |
| 22 | + add_widget_to_window(check_btn, x, y); |
21 | 23 | }
|
22 | 24 |
|
23 | | -void changeWindowBorderColor(Window window, long color) { |
24 | | - XSetWindowBorder(display, window, color); |
| 25 | +void add_entry(char default_text[], int x, int y) { |
| 26 | + GtkWidget *entry = gtk_entry_new(); |
| 27 | + if(!strcmp(default_text, "")) { |
| 28 | + gtk_entry_set_text(GTK_ENTRY(entry), default_text); |
| 29 | + } |
| 30 | + add_widget_to_window(entry, x, y); |
25 | 31 | }
|
26 | 32 |
|
27 | | -void writeText(char[] text, int x, int y, Window window, long background, long foreground) { |
28 | | - gc = XCreateGC(display, window, 0, 0); |
29 | | - XSetBackground(display, gc, (long) background); |
30 | | - XSetForeground(display, gc, (long) foreground); |
31 | | - XDrawString(display, window, gc, x, y, text, strlen(text)); |
| 33 | +void show_message_dialog(char title[], char message[]) { |
| 34 | + // TODO |
32 | 35 | }
|
33 | 36 |
|
34 | | -longrgb(intr, intg, intb) { |
35 | | - returnb+ (g<<8) + (r<<16); |
| 37 | +voidadd_menu_bar() { |
| 38 | + // TODO |
36 | 39 | }
|
37 | 40 |
|
38 | | -longred() { |
39 | | - returnrgb(255, 0, 0); |
| 41 | +voidadd_radio() { |
| 42 | + // TODO |
40 | 43 | }
|
41 | 44 |
|
42 | | -long green() { |
43 | | - return rgb(0, 255, 0); |
| 45 | +void add_link_button(char link[], char label[], int x, int y) { |
| 46 | + GtkWidget *link_btn = gtk_link_button_new_with_label(link, label); |
| 47 | + add_widget_to_window(link_btn, x, y); |
44 | 48 | }
|
45 | 49 |
|
46 | | -long blue() { |
47 | | - return rgb(0, 0, 255); |
| 50 | +void add_switch(int active, int x, int y) { |
| 51 | + GtkWidget *switch_btn = gtk_switch_new(); |
| 52 | + gtk_switch_set_state(GTK_SWITCH(switch_btn), active); |
| 53 | + add_widget_to_window(switch_btn, x, y); |
48 | 54 | }
|
49 | 55 |
|
50 | | -long white() { |
51 | | - return rgb(255, 255, 255); |
| 56 | +void add_label(char text[], int x, int y) { |
| 57 | + GtkWidget *label = gtk_label_new(text); |
| 58 | + add_widget_to_window(label, x, y); |
52 | 59 | }
|
53 | 60 |
|
54 | | -long black() { |
55 | | - return rgb(0, 0, 0); |
| 61 | +void add_image(char file[], int x, int y) { |
| 62 | + GtkWidget *image = gtk_image_new_from_file(file); |
| 63 | + add_widget_to_window(image, x, y); |
56 | 64 | }
|
57 | 65 |
|
58 | | -int start(int x, int y, int width, int height, int border, long borderColor, long rgb, char[] windowTitle) { |
59 | | - XEvent xev; |
| 66 | +static void activate(GtkApplication *app, gpointer user_data) { |
| 67 | + root = gtk_application_window_new(app); |
| 68 | + gtk_window_set_title(GTK_WINDOW(root), window_title); |
| 69 | + gtk_window_set_default_size(GTK_WINDOW(root), window_width, window_height); |
| 70 | + fixed = gtk_fixed_new(); |
60 | 71 |
|
61 | | - if((display = XOpenDisplay(NULL)) == NULL) { |
62 | | - printf("%s\n", "Couldn't open display"); |
63 | | - return 1; |
64 | | - } |
| 72 | + g_signal_connect(root, "destroy", G_CALLBACK(gtk_main_quit), NULL); |
65 | 73 |
|
66 | | - // Get default screen and root window |
67 | | - screen = DefaultScreen(display); |
| 74 | + gtk_container_add(GTK_CONTAINER(root), fixed); |
| 75 | + gtk_widget_show_all(root); |
| 76 | +} |
68 | 77 |
|
69 | | -root=XCreateSimpleWindow(display, RootWindow(display, screen), x, y, width, height, border, (long) borderColor, (long) rgb); |
70 | | - XSetStandardProperties(display, root, windowTitle, "", None, NULL, 0, NULL); |
71 | | - // Map window to display server |
72 | | - XMapWindow(display, root); |
| 78 | +intstart(chartitle[], intwidth, intheight) { |
| 79 | + window_height=height; |
| 80 | + window_width=width; |
| 81 | + strcpy(window_title, title); |
73 | 82 |
|
74 | | - while(True) { |
75 | | - XNextEvent(display, &xev); |
76 | | - } |
| 83 | + GtkApplication *app; |
| 84 | + app = gtk_application_new("grephq.phpdesktop", G_APPLICATION_FLAGS_NONE); |
| 85 | + g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); |
| 86 | + int status = g_application_run(G_APPLICATION(app), 0, NULL); |
| 87 | + g_object_unref(app); |
77 | 88 |
|
78 | | - // Unmap window |
79 | | - XUnmapWindow(display, root); |
80 | | - XDestroyWindow(display, root); |
81 | | - // Close connection with display server |
82 | | - XCloseDisplay(display); |
83 | | - return 0; |
| 89 | + return status; |
84 | 90 | }
|
0 commit comments