Skip to content

Commit

Permalink
focus_enter and focus_leave events
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Oct 9, 2022
1 parent b4e2761 commit 80cfaca
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 6 deletions.
12 changes: 11 additions & 1 deletion demos/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ static void text(char const *s, void *user_data) {

}

static void focus_enter(void *user_data) {

}

static void focus_leave(void *user_data) {

}

static void create_window(void *user_data) {
struct demo *demo = user_data;
struct gral_window_interface interface = {
Expand All @@ -86,7 +94,9 @@ static void create_window(void *user_data) {
&scroll,
&key_press,
&key_release,
&text
&text,
&focus_enter,
&focus_leave
};
demo->window = gral_window_create(demo->application, 800, 600, "gral clipboard demo", &interface, demo);
}
Expand Down
12 changes: 11 additions & 1 deletion demos/cursors.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ static void text(char const *s, void *user_data) {

}

static void focus_enter(void *user_data) {

}

static void focus_leave(void *user_data) {

}

static void create_window(void *user_data) {
struct demo *demo = user_data;
struct gral_window_interface interface = {
Expand All @@ -112,7 +120,9 @@ static void create_window(void *user_data) {
&scroll,
&key_press,
&key_release,
&text
&text,
&focus_enter,
&focus_leave
};
demo->window = gral_window_create(demo->application, 400, 400, "gral cursors demo", &interface, demo);
demo->cursor = GRAL_CURSOR_DEFAULT;
Expand Down
12 changes: 11 additions & 1 deletion demos/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ static void text(char const *s, void *user_data) {

}

static void focus_enter(void *user_data) {

}

static void focus_leave(void *user_data) {

}

static void create_window(void *user_data) {
struct demo *demo = user_data;
struct gral_window_interface interface = {
Expand All @@ -154,7 +162,9 @@ static void create_window(void *user_data) {
&scroll,
&key_press,
&key_release,
&text
&text,
&focus_enter,
&focus_leave
};
demo->window = gral_window_create(demo->application, 600, 400, "gral draw demo", &interface, demo);
gral_window_set_minimum_size(demo->window, 600, 400);
Expand Down
12 changes: 11 additions & 1 deletion demos/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ static void text(char const *s, void *user_data) {
}
}

static void focus_enter(void *user_data) {
printf("focus enter\n");
}

static void focus_leave(void *user_data) {
printf("focus leave\n");
}

static int timer(void *user_data) {
printf("timer\n");
return 1;
Expand All @@ -118,7 +126,9 @@ static void create_window(void *user_data) {
&scroll,
&key_press,
&key_release,
&text
&text,
&focus_enter,
&focus_leave
};
demo->window = gral_window_create(demo->application, 600, 400, "gral events demo", &interface, demo);
demo->timer = gral_window_create_timer(demo->window, 1000, &timer, &timer_destroy, demo);
Expand Down
12 changes: 11 additions & 1 deletion demos/file_dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ static void text(char const *s, void *user_data) {

}

static void focus_enter(void *user_data) {

}

static void focus_leave(void *user_data) {

}

static void create_window(void *user_data) {
struct demo *demo = user_data;
struct gral_window_interface interface = {
Expand All @@ -96,7 +104,9 @@ static void create_window(void *user_data) {
&scroll,
&key_press,
&key_release,
&text
&text,
&focus_enter,
&focus_leave
};
demo->window = gral_window_create(demo->application, 600, 400, "gral file dialog demo", &interface, demo);
}
Expand Down
12 changes: 11 additions & 1 deletion demos/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ static void text(char const *s, void *user_data) {

}

static void focus_enter(void *user_data) {

}

static void focus_leave(void *user_data) {

}

static void create_window(void *user_data) {
struct demo *demo = user_data;
struct gral_window_interface interface = {
Expand All @@ -101,7 +109,9 @@ static void create_window(void *user_data) {
&scroll,
&key_press,
&key_release,
&text
&text,
&focus_enter,
&focus_leave
};
demo->window = gral_window_create(demo->application, 600, 400, "gral text demo", &interface, demo);
struct gral_font *font = gral_font_create_default(demo->window, 16.0f);
Expand Down
2 changes: 2 additions & 0 deletions gral.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ struct gral_window_interface {
void (*key_press)(int key, int scan_code, int modifiers, void *user_data);
void (*key_release)(int key, int scan_code, void *user_data);
void (*text)(char const *s, void *user_data);
void (*focus_enter)(void *user_data);
void (*focus_leave)(void *user_data);
};
struct gral_timer;
struct gral_file;
Expand Down
12 changes: 12 additions & 0 deletions gral_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,16 @@ static void gral_area_commit(GtkIMContext *context, gchar *str, gpointer user_da
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(GTK_WIDGET(user_data)));
window->interface.text(str, window->user_data);
}
static gboolean gral_area_focus_in_event(GtkWidget *widget, GdkEventFocus *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
window->interface.focus_enter(window->user_data);
return GDK_EVENT_STOP;
}
static gboolean gral_area_focus_out_event(GtkWidget *widget, GdkEventFocus *event) {
GralWindow *window = GRAL_WINDOW(gtk_widget_get_parent(widget));
window->interface.focus_leave(window->user_data);
return GDK_EVENT_STOP;
}
static void gral_area_dispose(GObject *object) {
GralArea *area = GRAL_AREA(object);
g_clear_object(&area->im_context);
Expand All @@ -472,6 +482,8 @@ static void gral_area_class_init(GralAreaClass *class) {
widget_class->scroll_event = gral_area_scroll_event;
widget_class->key_press_event = gral_area_key_press_event;
widget_class->key_release_event = gral_area_key_release_event;
widget_class->focus_in_event = gral_area_focus_in_event;
widget_class->focus_out_event = gral_area_focus_out_event;
GObjectClass *object_class = G_OBJECT_CLASS(class);
object_class->dispose = gral_area_dispose;
}
Expand Down
6 changes: 6 additions & 0 deletions gral_macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ @implementation GralWindow
- (BOOL)windowShouldClose:(id)sender {
return interface.close(user_data);
}
- (void)windowDidBecomeKey:(NSNotification *)notification {
interface.focus_enter(user_data);
}
- (void)windowDidResignKey:(NSNotification *)notification {
interface.focus_leave(user_data);
}
@end

@interface GralView: NSView<NSTextInputClient> {
Expand Down
6 changes: 6 additions & 0 deletions gral_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
}
return 0;
}
case WM_SETFOCUS:
window_data->iface.focus_enter(window_data->user_data);
return 0;
case WM_KILLFOCUS:
window_data->iface.focus_leave(window_data->user_data);
return 0;
case WM_TIMER:
{
gral_timer *timer = (gral_timer *)wParam;
Expand Down

0 comments on commit 80cfaca

Please sign in to comment.