9 #include <sys/socket.h>
15 #include "oswald-ui.h"
16 #include "Fonts.h" // the MetaWatch fonts
18 #define BITMAP_WIDTH 192
19 #define BITMAP_HEIGHT 192
21 void set_pixel(oswald_ui *ui, gint x, gint y, gboolean state)
23 GdkRectangle update_rect;
29 update_rect.x = ix - 5;
30 update_rect.y = iy - 5;
31 update_rect.width = 10;
32 update_rect.height = 10;
34 gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix, iy);
35 gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix+1, iy);
36 gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix, iy+1);
37 gdk_draw_point(GDK_DRAWABLE(ui->pixmap), state ? ui->darea->style->black_gc : ui->darea->style->white_gc, ix+1, iy+1);
39 gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
42 void clear_display(oswald_ui *ui)
44 GdkRectangle update_rect;
48 update_rect.width = BITMAP_WIDTH;
49 update_rect.height = BITMAP_HEIGHT;
51 gdk_draw_rectangle (ui->pixmap,
52 ui->darea->style->white_gc,
55 ui->darea->allocation.width,
56 ui->darea->allocation.height);
58 gtk_widget_draw (GTK_WIDGET(ui->darea), &update_rect);
62 configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
64 oswald_ui *ui = (oswald_ui *)user_data;
67 gdk_pixmap_unref(ui->pixmap);
69 ui->pixmap = gdk_pixmap_new(widget->window,
70 widget->allocation.width,
71 widget->allocation.height,
73 gdk_draw_rectangle (ui->pixmap,
74 widget->style->white_gc,
77 widget->allocation.width,
78 widget->allocation.height);
84 expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
86 oswald_ui *ui = (oswald_ui *)user_data;
88 gdk_draw_pixmap(widget->window,
89 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
91 event->area.x, event->area.y,
92 event->area.x, event->area.y,
93 event->area.width, event->area.height);
98 static void create_mainwin(oswald_ui *ui)
100 GtkWidget *hb, *vb, *btn;
104 ui->mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
105 // gtk_window_set_default_size (GTK_WINDOW (ui->mainwin), 440, 240);
106 g_signal_connect(G_OBJECT(ui->mainwin), "destroy", gtk_main_quit, NULL);
108 hb = gtk_hbox_new(FALSE, 5);
109 gtk_container_add(GTK_CONTAINER(ui->mainwin), hb);
111 vb = gtk_vbox_new(FALSE, 5);
112 gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
114 btn = gtk_button_new_with_label(" D ");
115 gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
117 btn = gtk_button_new_with_label(" E ");
118 gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
120 btn = gtk_button_new_with_label(" F ");
121 gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
123 ui->darea = gtk_drawing_area_new ();
124 gtk_box_pack_start (GTK_BOX(hb), GTK_WIDGET(ui->darea), FALSE, FALSE, 5);
125 gtk_drawing_area_size (GTK_DRAWING_AREA(ui->darea), BITMAP_WIDTH, BITMAP_HEIGHT);
127 gtk_signal_connect (GTK_OBJECT (ui->darea), "expose_event", (GtkSignalFunc) expose_event, ui);
128 gtk_signal_connect (GTK_OBJECT (ui->darea), "configure_event", (GtkSignalFunc) configure_event, ui);
129 // gtk_signal_connect (GTK_OBJECT (drawing_area), "motion_notify_event", (GtkSignalFunc) motion_notify_event, ui);
130 // gtk_signal_connect (GTK_OBJECT (drawing_area), "button_press_event", (GtkSignalFunc) button_press_event, ui);
132 gtk_widget_set_events (GTK_WIDGET(ui->darea), GDK_EXPOSURE_MASK
133 | GDK_LEAVE_NOTIFY_MASK
134 | GDK_BUTTON_PRESS_MASK
135 | GDK_POINTER_MOTION_MASK
136 | GDK_POINTER_MOTION_HINT_MASK);
138 vb = gtk_vbox_new(FALSE, 5);
139 gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5);
141 btn = gtk_button_new_with_label(" A ");
142 gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
144 btn = gtk_button_new_with_label(" B ");
145 gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
147 btn = gtk_button_new_with_label(" C ");
148 gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10);
150 gtk_widget_show_all(ui->mainwin);
153 gboolean app_tmo_handler (gpointer userdata)
155 oswald_ui *ui = (oswald_ui *)userdata;
157 // fprintf(stderr, "tmo...\n");
159 if (ui->OnIdleScreen) {
160 update_idle_time_date(ui);
163 // go back to idle screen after IDLE_TIMEOUT seconds
164 if ((time(NULL) - ui->idle_tmo) > ui->conf.idle_tmo /*IDLE_TIMEOUT*/)
165 create_main_screen(ui);
172 int main(int argc , char ** argv)
176 gtk_init (&argc, &argv);
180 //set_pixel(&ui, 48, 48, TRUE);
182 ui.OnIdleScreen = TRUE;
183 g_timeout_add_seconds(1, app_tmo_handler, &ui);