summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorP. F. Chimento <philip.chimento@gmail.com>2013-04-29 16:02:18 +0200
committerP. F. Chimento <philip.chimento@gmail.com>2013-04-29 16:02:18 +0200
commit449b4d8e8d7c907020665a7a64324f46de67a8bb (patch)
treec0ac5948257d40b636b2f59c1a625137784ab684
parent65fc04a83bfec371bb7cfb48d4b71c69deff6a79 (diff)
parenta568631122c96468601e08b59e69090e76ab3eb5 (diff)
Merge pull request #22 from endlessm#12
Issues/12 EosWindow based on eos-weather/window.py
-rw-r--r--endless/Makefile.am4
-rw-r--r--endless/eoswindow.c27
-rw-r--r--test/run-tests.h1
-rw-r--r--test/test-window.c58
4 files changed, 89 insertions, 1 deletions
diff --git a/endless/Makefile.am b/endless/Makefile.am
index cb5a259..b8d1a59 100644
--- a/endless/Makefile.am
+++ b/endless/Makefile.am
@@ -22,8 +22,12 @@ libendless_@EOS_SDK_API_VERSION@_la_SOURCES = \
$(endless_public_installed_headers) \
$(endless_private_installed_headers) \
$(endless_library_sources)
+# Defining G_LOG_DOMAIN allows you to run any program with
+# G_MESSAGES_DEBUG=EndlessSDK ./myprogram
+# and turn on debug messages
libendless_@EOS_SDK_API_VERSION@_la_CPPFLAGS = \
@EOS_SDK_CFLAGS@ \
+ -DG_LOG_DOMAIN=\"EndlessSDK\" \
-DCOMPILING_EOS_SDK
libendless_@EOS_SDK_API_VERSION@_la_CFLAGS = $(AM_CFLAGS)
libendless_@EOS_SDK_API_VERSION@_la_LIBADD = @EOS_SDK_LIBS@
diff --git a/endless/eoswindow.c b/endless/eoswindow.c
index 29032a6..7cd7f28 100644
--- a/endless/eoswindow.c
+++ b/endless/eoswindow.c
@@ -12,7 +12,22 @@
* @short_description: A window for your application
* @title: Window
*
- * Stub
+ * The #EosWindow class is where you put your application's user interface.
+ * You should create a class that extends #EosWindow.
+ *
+ * Create the interface in your window class's _init() function, like this:
+ * |[
+ * const SmokeGrinderWindow = new Lang.Class({
+ * Name: 'SmokeGrinderWindow',
+ * Extends: Endless.Window,
+ *
+ * _init(): function (props) {
+ * this.parent(props);
+ * this._button = Gtk.Button({label: 'Push me'});
+ * this.add(this._button);
+ * },
+ * });
+ * ]|
*/
G_DEFINE_TYPE (EosWindow, eos_window, GTK_TYPE_APPLICATION_WINDOW)
@@ -87,6 +102,13 @@ eos_window_class_init (EosWindowClass *klass)
object_class->get_property = eos_window_get_property;
object_class->set_property = eos_window_set_property;
+ /**
+ * EosWindow:application:
+ *
+ * The #EosApplication that this window is associated with. See also
+ * #GtkWindow:application; the difference is that #EosWindow:application
+ * cannot be %NULL and must be an #EosApplication.
+ */
eos_window_props[PROP_APPLICATION] =
g_param_spec_object ("application", "Application",
"Application associated with this window",
@@ -100,6 +122,9 @@ static void
eos_window_init (EosWindow *self)
{
self->priv = WINDOW_PRIVATE (self);
+
+ gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
+ gtk_window_maximize (GTK_WINDOW (self));
}
/* Public API */
diff --git a/test/run-tests.h b/test/run-tests.h
index e60000f..8d18015 100644
--- a/test/run-tests.h
+++ b/test/run-tests.h
@@ -3,6 +3,7 @@
#ifndef RUN_TESTS_H
#define RUN_TESTS_H
+#define TEST_LOG_DOMAIN "EndlessSDK"
#define TEST_APPLICATION_ID "com.endlessm.example.test"
#define ADD_APP_WINDOW_TEST(path, test_func) \
diff --git a/test/test-window.c b/test/test-window.c
index 831d94c..9127120 100644
--- a/test/test-window.c
+++ b/test/test-window.c
@@ -6,6 +6,10 @@
#include "run-tests.h"
+#define EXPECTED_NULL_APPLICATION_ERRMSG \
+ "In order to create a window, you must have an application for it to " \
+ "connect to."
+
static void
test_assign_application (GApplication *app)
{
@@ -17,8 +21,62 @@ test_assign_application (GApplication *app)
gtk_widget_destroy (win);
}
+static void
+test_application_not_null (GApplication *app)
+{
+ GtkWidget *win;
+
+ g_test_expect_message (TEST_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ EXPECTED_NULL_APPLICATION_ERRMSG);
+
+ win = eos_window_new (NULL);
+
+ g_test_assert_expected_messages ();
+
+ gtk_widget_destroy (win);
+ g_application_release (app);
+ g_application_quit (app); /* Doesn't quit when win is destroyed */
+}
+
+static void
+test_screen_size (GApplication *app)
+{
+ GtkWidget *win = eos_window_new (EOS_APPLICATION (app));
+ GdkRectangle screen_size, window_size;
+ GdkScreen *default_screen = gdk_screen_get_default ();
+ gint monitor = 0;
+
+ /* If more than one monitor, find out which one to use */
+ if (gdk_screen_get_n_monitors (default_screen) != 1)
+ {
+ GdkWindow *gdkwindow;
+
+ /* Realize the window so that its GdkWindow is not NULL */
+ gtk_widget_realize (GTK_WIDGET (win));
+ gdkwindow = gtk_widget_get_window (GTK_WIDGET (win));
+ monitor = gdk_screen_get_monitor_at_window (default_screen, gdkwindow);
+ }
+
+ gdk_screen_get_monitor_workarea (default_screen, monitor, &screen_size);
+
+ gtk_widget_show_now (GTK_WIDGET (win));
+
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ gtk_widget_get_allocation (GTK_WIDGET (win), &window_size);
+
+ g_assert_cmpint (screen_size.width, ==, window_size.width);
+ g_assert_cmpint (screen_size.height, ==, window_size.height);
+
+ gtk_widget_destroy (win);
+}
+
void
add_window_tests (void)
{
ADD_APP_WINDOW_TEST ("/window/assign-application", test_assign_application);
+ ADD_APP_WINDOW_TEST ("/window/application-not-null",
+ test_application_not_null);
+ ADD_APP_WINDOW_TEST ("/window/screen-size", test_screen_size);
}