Commit 02b2f573 authored by Jonny Lamb's avatar Jonny Lamb
Browse files

maynard: change coding style to be more consistent

This style is way more GTKy. shell-helper.c is left using wayland's
style as it's much more wayland than it is GTK.
parent a4ae2f5a
......@@ -73,11 +73,9 @@ struct desktop {
};
static gboolean panel_window_enter_cb (GtkWidget *widget,
GdkEventCrossing *event,
struct desktop *desktop);
GdkEventCrossing *event, struct desktop *desktop);
static gboolean panel_window_leave_cb (GtkWidget *widget,
GdkEventCrossing *event,
struct desktop *desktop);
GdkEventCrossing *event, struct desktop *desktop);
static gboolean
connect_enter_leave_signals (gpointer data)
......@@ -104,7 +102,7 @@ connect_enter_leave_signals (gpointer data)
}
static void
desktop_shell_configure(void *data,
desktop_shell_configure (void *data,
struct desktop_shell *desktop_shell,
uint32_t edges,
struct wl_surface *surface,
......@@ -122,31 +120,26 @@ desktop_shell_configure(void *data,
gtk_window_resize (GTK_WINDOW (desktop->panel->window),
MAYNARD_PANEL_WIDTH, window_height);
maynard_launcher_calculate (MAYNARD_LAUNCHER(desktop->launcher_grid->window),
maynard_launcher_calculate (MAYNARD_LAUNCHER (desktop->launcher_grid->window),
&grid_width, &grid_height, NULL);
gtk_widget_set_size_request (desktop->launcher_grid->window,
grid_width,
grid_height);
grid_width, grid_height);
shell_helper_move_surface(desktop->helper,
desktop->panel->surface,
shell_helper_move_surface (desktop->helper, desktop->panel->surface,
0, (height - window_height) / 2);
gtk_window_resize (GTK_WINDOW (desktop->clock->window),
MAYNARD_CLOCK_WIDTH,
MAYNARD_CLOCK_HEIGHT);
MAYNARD_CLOCK_WIDTH, MAYNARD_CLOCK_HEIGHT);
shell_helper_move_surface(desktop->helper,
desktop->clock->surface,
MAYNARD_PANEL_WIDTH,
(height - window_height) / 2);
shell_helper_move_surface (desktop->helper, desktop->clock->surface,
MAYNARD_PANEL_WIDTH, (height - window_height) / 2);
shell_helper_move_surface(desktop->helper,
shell_helper_move_surface (desktop->helper,
desktop->launcher_grid->surface,
- grid_width,
((height - window_height) / 2) + MAYNARD_CLOCK_HEIGHT);
desktop_shell_desktop_ready(desktop->shell);
desktop_shell_desktop_ready (desktop->shell);
/* TODO: why does the panel signal leave on drawing for
* startup? we don't want to have to have this silly
......@@ -155,14 +148,15 @@ desktop_shell_configure(void *data,
}
static void
desktop_shell_prepare_lock_surface(void *data,
desktop_shell_prepare_lock_surface (void *data,
struct desktop_shell *desktop_shell)
{
desktop_shell_unlock (desktop_shell);
}
static void
desktop_shell_grab_cursor(void *data, struct desktop_shell *desktop_shell,
desktop_shell_grab_cursor (void *data,
struct desktop_shell *desktop_shell,
uint32_t cursor)
{
}
......@@ -174,18 +168,22 @@ static const struct desktop_shell_listener listener = {
};
static void
launcher_grid_toggle (GtkWidget *widget, struct desktop *desktop)
launcher_grid_toggle (GtkWidget *widget,
struct desktop *desktop)
{
if (desktop->grid_visible) {
shell_helper_slide_surface_back(desktop->helper,
if (desktop->grid_visible)
{
shell_helper_slide_surface_back (desktop->helper,
desktop->launcher_grid->surface);
} else {
}
else
{
int width;
gtk_widget_get_size_request (desktop->launcher_grid->window,
&width, NULL);
shell_helper_slide_surface(desktop->helper,
shell_helper_slide_surface (desktop->helper,
desktop->launcher_grid->surface,
width + MAYNARD_PANEL_WIDTH, 0);
}
......@@ -203,18 +201,18 @@ launcher_grid_create (struct desktop *desktop)
memset (launcher_grid, 0, sizeof *launcher_grid);
launcher_grid->window = maynard_launcher_new (desktop->background->window);
gdk_window = gtk_widget_get_window(launcher_grid->window);
launcher_grid->surface = gdk_wayland_window_get_wl_surface(gdk_window);
gdk_window = gtk_widget_get_window (launcher_grid->window);
launcher_grid->surface = gdk_wayland_window_get_wl_surface (gdk_window);
gdk_wayland_window_set_use_custom_surface(gdk_window);
shell_helper_add_surface_to_layer(desktop->helper,
gdk_wayland_window_set_use_custom_surface (gdk_window);
shell_helper_add_surface_to_layer (desktop->helper,
launcher_grid->surface,
desktop->panel->surface);
g_signal_connect(launcher_grid->window, "app-launched",
G_CALLBACK(launcher_grid_toggle), desktop);
g_signal_connect (launcher_grid->window, "app-launched",
G_CALLBACK (launcher_grid_toggle), desktop);
gtk_widget_show_all(launcher_grid->window);
gtk_widget_show_all (launcher_grid->window);
desktop->launcher_grid = launcher_grid;
}
......@@ -235,19 +233,19 @@ clock_create (struct desktop *desktop)
struct element *clock;
GdkWindow *gdk_window;
clock = malloc(sizeof *clock);
memset(clock, 0, sizeof *clock);
clock = malloc (sizeof *clock);
memset (clock, 0, sizeof *clock);
clock->window = maynard_clock_new();
clock->window = maynard_clock_new ();
g_signal_connect (clock->window, "volume-changed",
G_CALLBACK (volume_changed_cb), desktop);
gdk_window = gtk_widget_get_window(clock->window);
clock->surface = gdk_wayland_window_get_wl_surface(gdk_window);
gdk_window = gtk_widget_get_window (clock->window);
clock->surface = gdk_wayland_window_get_wl_surface (gdk_window);
gdk_wayland_window_set_use_custom_surface(gdk_window);
shell_helper_add_surface_to_layer(desktop->helper, clock->surface,
gdk_wayland_window_set_use_custom_surface (gdk_window);
shell_helper_add_surface_to_layer (desktop->helper, clock->surface,
desktop->panel->surface);
gtk_widget_show_all (clock->window);
......@@ -263,17 +261,22 @@ button_toggled_cb (struct desktop *desktop,
*visible = !*visible;
*not_visible = FALSE;
if (desktop->system_visible) {
if (desktop->system_visible)
{
maynard_clock_show_section (MAYNARD_CLOCK (desktop->clock->window),
MAYNARD_CLOCK_SECTION_SYSTEM);
maynard_panel_show_previous (MAYNARD_PANEL (desktop->panel->window),
MAYNARD_PANEL_BUTTON_SYSTEM);
} else if (desktop->volume_visible) {
}
else if (desktop->volume_visible)
{
maynard_clock_show_section (MAYNARD_CLOCK (desktop->clock->window),
MAYNARD_CLOCK_SECTION_VOLUME);
maynard_panel_show_previous (MAYNARD_PANEL (desktop->panel->window),
MAYNARD_PANEL_BUTTON_VOLUME);
} else {
}
else
{
maynard_clock_show_section (MAYNARD_CLOCK (desktop->clock->window),
MAYNARD_CLOCK_SECTION_CLOCK);
maynard_panel_show_previous (MAYNARD_PANEL (desktop->panel->window),
......@@ -304,24 +307,25 @@ panel_window_enter_cb (GtkWidget *widget,
GdkEventCrossing *event,
struct desktop *desktop)
{
if (desktop->initial_panel_timeout_id > 0) {
if (desktop->initial_panel_timeout_id > 0)
{
g_source_remove (desktop->initial_panel_timeout_id);
desktop->initial_panel_timeout_id = 0;
}
if (desktop->hide_panel_idle_id > 0) {
if (desktop->hide_panel_idle_id > 0)
{
g_source_remove (desktop->hide_panel_idle_id);
desktop->hide_panel_idle_id = 0;
return;
}
shell_helper_slide_surface_back(desktop->helper,
shell_helper_slide_surface_back (desktop->helper,
desktop->panel->surface);
shell_helper_slide_surface_back(desktop->helper,
shell_helper_slide_surface_back (desktop->helper,
desktop->clock->surface);
maynard_panel_set_expand(MAYNARD_PANEL(desktop->panel->window),
TRUE);
maynard_panel_set_expand (MAYNARD_PANEL (desktop->panel->window), TRUE);
return FALSE;
}
......@@ -337,15 +341,14 @@ leave_panel_idle_cb (gpointer data)
gtk_window_get_size (GTK_WINDOW (desktop->clock->window),
&width, NULL);
shell_helper_slide_surface(desktop->helper,
shell_helper_slide_surface (desktop->helper,
desktop->panel->surface,
MAYNARD_VERTICAL_CLOCK_WIDTH - MAYNARD_PANEL_WIDTH, 0);
shell_helper_slide_surface(desktop->helper,
shell_helper_slide_surface (desktop->helper,
desktop->clock->surface,
MAYNARD_VERTICAL_CLOCK_WIDTH - MAYNARD_PANEL_WIDTH - width, 0);
maynard_panel_set_expand(MAYNARD_PANEL(desktop->panel->window),
FALSE);
maynard_panel_set_expand (MAYNARD_PANEL (desktop->panel->window), FALSE);
maynard_clock_show_section (MAYNARD_CLOCK (desktop->clock->window),
MAYNARD_CLOCK_SECTION_CLOCK);
......@@ -362,7 +365,8 @@ panel_window_leave_cb (GtkWidget *widget,
GdkEventCrossing *event,
struct desktop *desktop)
{
if (desktop->initial_panel_timeout_id > 0) {
if (desktop->initial_panel_timeout_id > 0)
{
g_source_remove (desktop->initial_panel_timeout_id);
desktop->initial_panel_timeout_id = 0;
}
......@@ -392,55 +396,55 @@ static void
favorite_launched_cb (MaynardPanel *panel,
struct desktop *desktop)
{
if (desktop->grid_visible) {
if (desktop->grid_visible)
launcher_grid_toggle (desktop->launcher_grid->window, desktop);
}
panel_window_leave_cb (NULL, NULL, desktop);
}
static void
panel_create(struct desktop *desktop)
panel_create (struct desktop *desktop)
{
struct element *panel;
GdkWindow *gdk_window;
panel = malloc(sizeof *panel);
memset(panel, 0, sizeof *panel);
panel = malloc (sizeof *panel);
memset (panel, 0, sizeof *panel);
panel->window = maynard_panel_new();
panel->window = maynard_panel_new ();
g_signal_connect(panel->window, "app-menu-toggled",
G_CALLBACK(launcher_grid_toggle), desktop);
g_signal_connect(panel->window, "system-toggled",
G_CALLBACK(system_toggled_cb), desktop);
g_signal_connect(panel->window, "volume-toggled",
G_CALLBACK(volume_toggled_cb), desktop);
g_signal_connect(panel->window, "favorite-launched",
G_CALLBACK(favorite_launched_cb), desktop);
g_signal_connect (panel->window, "app-menu-toggled",
G_CALLBACK (launcher_grid_toggle), desktop);
g_signal_connect (panel->window, "system-toggled",
G_CALLBACK (system_toggled_cb), desktop);
g_signal_connect (panel->window, "volume-toggled",
G_CALLBACK (volume_toggled_cb), desktop);
g_signal_connect (panel->window, "favorite-launched",
G_CALLBACK (favorite_launched_cb), desktop);
desktop->initial_panel_timeout_id =
g_timeout_add_seconds(2, panel_hide_timeout_cb, desktop);
g_timeout_add_seconds (2, panel_hide_timeout_cb, desktop);
/* set it up as the panel */
gdk_window = gtk_widget_get_window(panel->window);
gdk_wayland_window_set_use_custom_surface(gdk_window);
panel->surface = gdk_wayland_window_get_wl_surface(gdk_window);
desktop_shell_set_user_data(desktop->shell, desktop);
desktop_shell_set_panel(desktop->shell, desktop->output,
panel->surface);
desktop_shell_set_panel_position(desktop->shell,
gdk_window = gtk_widget_get_window (panel->window);
gdk_wayland_window_set_use_custom_surface (gdk_window);
panel->surface = gdk_wayland_window_get_wl_surface (gdk_window);
desktop_shell_set_user_data (desktop->shell, desktop);
desktop_shell_set_panel (desktop->shell, desktop->output, panel->surface);
desktop_shell_set_panel_position (desktop->shell,
DESKTOP_SHELL_PANEL_POSITION_LEFT);
gtk_widget_show_all(panel->window);
gtk_widget_show_all (panel->window);
desktop->panel = panel;
}
/* Expose callback for the drawing area */
static gboolean
draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
draw_cb (GtkWidget *widget,
cairo_t *cr,
gpointer data)
{
struct desktop *desktop = data;
......@@ -452,7 +456,8 @@ draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
/* Destroy handler for the window */
static void
destroy_cb (GObject *object, gpointer data)
destroy_cb (GObject *object,
gpointer data)
{
gtk_main_quit ();
}
......@@ -486,21 +491,22 @@ scale_background (GdkPixbuf *original_pixbuf)
}
static void
background_create(struct desktop *desktop)
background_create (struct desktop *desktop)
{
GdkWindow *gdk_window;
struct element *background;
const gchar *filename;
GdkPixbuf *unscaled_background;
background = malloc(sizeof *background);
memset(background, 0, sizeof *background);
background = malloc (sizeof *background);
memset (background, 0, sizeof *background);
filename = g_getenv("BACKGROUND");
filename = g_getenv ("BACKGROUND");
if (filename == NULL)
filename = DEFAULT_BACKGROUND;
unscaled_background = gdk_pixbuf_new_from_file (filename, NULL);
if (!unscaled_background) {
if (!unscaled_background)
{
g_message ("Could not load background. "
"Do you have kdewallpapers installed?");
exit (EXIT_FAILURE);
......@@ -509,7 +515,7 @@ background_create(struct desktop *desktop)
background->pixbuf = scale_background (unscaled_background);
g_object_unref (unscaled_background);
background->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
background->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (background->window, "destroy",
G_CALLBACK (destroy_cb), NULL);
......@@ -517,25 +523,25 @@ background_create(struct desktop *desktop)
g_signal_connect (background->window, "draw",
G_CALLBACK (draw_cb), desktop);
gtk_window_set_title(GTK_WINDOW(background->window), "maynard");
gtk_window_set_decorated(GTK_WINDOW(background->window), FALSE);
gtk_widget_realize(background->window);
gtk_window_set_title (GTK_WINDOW (background->window), "maynard");
gtk_window_set_decorated (GTK_WINDOW (background->window), FALSE);
gtk_widget_realize (background->window);
gdk_window = gtk_widget_get_window(background->window);
gdk_wayland_window_set_use_custom_surface(gdk_window);
gdk_window = gtk_widget_get_window (background->window);
gdk_wayland_window_set_use_custom_surface (gdk_window);
background->surface = gdk_wayland_window_get_wl_surface(gdk_window);
desktop_shell_set_user_data(desktop->shell, desktop);
desktop_shell_set_background(desktop->shell, desktop->output,
background->surface = gdk_wayland_window_get_wl_surface (gdk_window);
desktop_shell_set_user_data (desktop->shell, desktop);
desktop_shell_set_background (desktop->shell, desktop->output,
background->surface);
desktop->background = background;
gtk_widget_show_all(background->window);
gtk_widget_show_all (background->window);
}
static void
css_setup(struct desktop *desktop)
css_setup (struct desktop *desktop)
{
GtkCssProvider *provider;
GFile *file;
......@@ -545,7 +551,8 @@ css_setup(struct desktop *desktop)
file = g_file_new_for_uri ("resource:///org/raspberry-pi/maynard/style.css");
if (!gtk_css_provider_load_from_file (provider, file, &error)) {
if (!gtk_css_provider_load_from_file (provider, file, &error))
{
g_warning ("Failed to load CSS file: %s", error->message);
g_clear_error (&error);
g_object_unref (file);
......@@ -559,28 +566,36 @@ css_setup(struct desktop *desktop)
}
static void
registry_handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version)
registry_handle_global (void *data,
struct wl_registry *registry,
uint32_t name,
const char *interface,
uint32_t version)
{
struct desktop *d = data;
if (!strcmp(interface, "desktop_shell")) {
d->shell = wl_registry_bind(registry, name,
if (!strcmp (interface, "desktop_shell"))
{
d->shell = wl_registry_bind (registry, name,
&desktop_shell_interface, 3);
desktop_shell_add_listener(d->shell, &listener, d);
} else if (!strcmp(interface, "wl_output")) {
desktop_shell_add_listener (d->shell, &listener, d);
}
else if (!strcmp (interface, "wl_output"))
{
/* TODO: create multiple outputs */
d->output = wl_registry_bind(registry, name,
d->output = wl_registry_bind (registry, name,
&wl_output_interface, 1);
} else if (!strcmp(interface, "shell_helper")) {
d->helper = wl_registry_bind(registry, name,
}
else if (!strcmp (interface, "shell_helper"))
{
d->helper = wl_registry_bind (registry, name,
&shell_helper_interface, 1);
}
}
static void
registry_handle_global_remove(void *data, struct wl_registry *registry,
registry_handle_global_remove (void *data,
struct wl_registry *registry,
uint32_t name)
{
}
......@@ -591,31 +606,33 @@ static const struct wl_registry_listener registry_listener = {
};
int
main(int argc, char *argv[])
main (int argc,
char *argv[])
{
struct desktop *desktop;
gdk_set_allowed_backends ("wayland");
gtk_init(&argc, &argv);
gtk_init (&argc, &argv);
g_resources_register (maynard_get_resource ());
desktop = malloc(sizeof *desktop);
desktop = malloc (sizeof *desktop);
desktop->output = NULL;
desktop->shell = NULL;
desktop->helper = NULL;
desktop->gdk_display = gdk_display_get_default();
desktop->gdk_display = gdk_display_get_default ();
desktop->display =
gdk_wayland_display_get_wl_display(desktop->gdk_display);
if (desktop->display == NULL) {
fprintf(stderr, "failed to get display: %m\n");
gdk_wayland_display_get_wl_display (desktop->gdk_display);
if (desktop->display == NULL)
{
fprintf (stderr, "failed to get display: %m\n");
return -1;
}
desktop->registry = wl_display_get_registry(desktop->display);
wl_registry_add_listener(desktop->registry,
desktop->registry = wl_display_get_registry (desktop->display);
wl_registry_add_listener (desktop->registry,
&registry_listener, desktop);
/* Wait until we have been notified about the compositor,
......@@ -627,16 +644,16 @@ main(int argc, char *argv[])
desktop->system_visible = FALSE;
desktop->volume_visible = FALSE;
css_setup(desktop);
background_create(desktop);
css_setup (desktop);
background_create (desktop);
/* panel needs to be first so the clock and launcher grid can
* be added to its layer */
panel_create(desktop);
clock_create(desktop);
panel_create (desktop);
clock_create (desktop);
launcher_grid_create (desktop);
gtk_main();
gtk_main ();
/* TODO cleanup */
return EXIT_SUCCESS;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment