-
Notifications
You must be signed in to change notification settings - Fork 4
/
callbacks.c
177 lines (157 loc) · 5.96 KB
/
callbacks.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* Screentest - CRT/LCD monitor testing utility.
* https://tobix.github.io/screentest/
* Copyright (C) 2001 Jan "Yenya" Kasprzak <kas@fi.muni.cz>
* Copyright (C) 2006-2017 Tobias Gruetzmacher <tobias-screentest@23.gs>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "callbacks.h"
#include "gettext.h"
#include "main.h"
#include "screentest_colors.h"
#define _(String) gettext(String)
int fg_count = SCREENTEST_COLORS_WHITE;
static GtkWidget *mainwin = NULL;
static struct test_ops *current_test = &basic_ops;
G_MODULE_EXPORT void on_mainwin_realize(GtkWidget *widget,
G_GNUC_UNUSED gpointer user_data) {
#ifndef DEBUG
gtk_window_fullscreen(GTK_WINDOW(widget));
#endif
mainwin = widget;
if (current_test->init != NULL)
current_test->init(widget);
}
G_MODULE_EXPORT gboolean
on_mainwin_button_press_event(GtkWidget *widget, GdkEventButton *event,
G_GNUC_UNUSED gpointer user_data) {
GObject *popup;
switch (event->button) {
case 1:
if (current_test->cycle != NULL) {
current_test->cycle(widget);
gdk_window_invalidate_rect(gtk_widget_get_window(mainwin), NULL, FALSE);
}
break;
case 2:
if (++fg_count >= SCREENTEST_COLORS_MAX)
fg_count = SCREENTEST_COLORS_WHITE;
*fg_color = fgcolors[fg_count];
gdk_window_invalidate_rect(gtk_widget_get_window(mainwin), NULL, FALSE);
break;
case 3:
popup = gtk_builder_get_object(builder, "popup");
#if GTK_CHECK_VERSION(3, 22, 0)
gtk_menu_popup_at_pointer(GTK_MENU(popup), (GdkEvent *)event);
#else // GTK_CHECK_VERSION(3,22,0)
gtk_menu_popup(GTK_MENU(popup), NULL, NULL, NULL, NULL, event->button,
event->time);
#endif // GTK_CHECK_VERSION(3,22,0)
break;
}
return TRUE;
}
/*
* FIXME: GTK_WINDOW_POPUP does not seem to be able to receive
* KeyPress events. How to enable this?
*/
G_MODULE_EXPORT gboolean on_mainwin_key_press_event(
G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEventKey *event,
G_GNUC_UNUSED gpointer user_data) {
gtk_main_quit();
return FALSE;
}
G_MODULE_EXPORT gboolean on_mainwin_draw_event(
GtkWidget *widget, cairo_t *cr, G_GNUC_UNUSED gpointer user_data) {
gdk_window_set_background_rgba(gtk_widget_get_window(widget), bg_color);
if (current_test && current_test->draw)
current_test->draw(widget, cr);
return TRUE;
}
G_MODULE_EXPORT void on_mode_change(GtkMenuItem *menuitem,
G_GNUC_UNUSED gpointer user_data) {
GtkCheckMenuItem *checkmenuitem = GTK_CHECK_MENU_ITEM(menuitem);
if (!gtk_check_menu_item_get_active(checkmenuitem)) {
if (current_test->close != NULL) {
current_test->close(mainwin);
current_test = NULL;
}
} else {
const char *test_name = gtk_buildable_get_name(GTK_BUILDABLE(menuitem));
g_assert(test_name != NULL);
GModule *exe = g_module_open(NULL, 0);
g_assert(exe != NULL);
gchar *test_struct = g_strconcat(test_name, "_ops", NULL);
if (g_module_symbol(exe, test_struct, (gpointer)¤t_test) != TRUE) {
GtkWidget *dialog = gtk_message_dialog_new(
GTK_WINDOW(mainwin),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, _("No implementation for the test \"%s\" found."),
test_name);
gtk_window_set_title(GTK_WINDOW(dialog), PACKAGE_NAME);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_main_quit();
}
free(test_struct);
g_module_close(exe);
if (current_test != NULL && current_test->init != NULL) {
current_test->init(mainwin);
}
gtk_widget_queue_draw(mainwin);
}
}
G_MODULE_EXPORT void on_fg_color_activate(G_GNUC_UNUSED GtkMenuItem *menuitem,
G_GNUC_UNUSED gpointer user_data) {
GObject *fg_color_selector;
fg_color_selector = gtk_builder_get_object(builder, "fg_color_selector");
gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(fg_color_selector), FALSE);
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(fg_color_selector), fg_color);
switch (gtk_dialog_run(GTK_DIALOG(fg_color_selector))) {
case GTK_RESPONSE_OK:
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(fg_color_selector), fg_color);
gdk_window_invalidate_rect(gtk_widget_get_window(mainwin), NULL, FALSE);
break;
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_DELETE_EVENT:
break;
default:
g_assert_not_reached();
}
gtk_widget_hide(GTK_WIDGET(fg_color_selector));
}
G_MODULE_EXPORT void on_bg_color_activate(G_GNUC_UNUSED GtkMenuItem *menuitem,
G_GNUC_UNUSED gpointer user_data) {
GObject *bg_color_selector;
bg_color_selector = gtk_builder_get_object(builder, "bg_color_selector");
gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(bg_color_selector), FALSE);
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(bg_color_selector), bg_color);
switch (gtk_dialog_run(GTK_DIALOG(bg_color_selector))) {
case GTK_RESPONSE_OK:
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(bg_color_selector), bg_color);
gdk_window_invalidate_rect(gtk_widget_get_window(mainwin), NULL, FALSE);
break;
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_DELETE_EVENT:
break;
default:
g_assert_not_reached();
}
gtk_widget_hide(GTK_WIDGET(bg_color_selector));
}