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
......@@ -45,599 +45,616 @@ extern char **environ; /* defined by libc */
#define DEFAULT_BACKGROUND "/usr/share/wallpapers/Hanami/contents/images/3872x2592.jpg"
struct element {
GtkWidget *window;
GdkPixbuf *pixbuf;
struct wl_surface *surface;
GtkWidget *window;
GdkPixbuf *pixbuf;
struct wl_surface *surface;
};
struct desktop {
struct wl_display *display;
struct wl_registry *registry;
struct desktop_shell *shell;
struct wl_output *output;
struct shell_helper *helper;
struct wl_display *display;
struct wl_registry *registry;
struct desktop_shell *shell;
struct wl_output *output;
struct shell_helper *helper;
GdkDisplay *gdk_display;
GdkDisplay *gdk_display;
struct element *background;
struct element *panel;
struct element *launcher_grid;
struct element *clock;
struct element *background;
struct element *panel;
struct element *launcher_grid;
struct element *clock;
guint initial_panel_timeout_id;
guint hide_panel_idle_id;
guint initial_panel_timeout_id;
guint hide_panel_idle_id;
gboolean grid_visible;
gboolean system_visible;
gboolean volume_visible;
gboolean grid_visible;
gboolean system_visible;
gboolean volume_visible;
};
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)
{
struct desktop *desktop = data;
GList *l;
struct desktop *desktop = data;
GList *l;
g_signal_connect (desktop->panel->window, "enter-notify-event",
G_CALLBACK (panel_window_enter_cb), desktop);
g_signal_connect (desktop->panel->window, "leave-notify-event",
G_CALLBACK (panel_window_leave_cb), desktop);
g_signal_connect (desktop->panel->window, "enter-notify-event",
G_CALLBACK (panel_window_enter_cb), desktop);
g_signal_connect (desktop->panel->window, "leave-notify-event",
G_CALLBACK (panel_window_leave_cb), desktop);
g_signal_connect (desktop->clock->window, "enter-notify-event",
G_CALLBACK (panel_window_enter_cb), desktop);
g_signal_connect (desktop->clock->window, "leave-notify-event",
G_CALLBACK (panel_window_leave_cb), desktop);
g_signal_connect (desktop->clock->window, "enter-notify-event",
G_CALLBACK (panel_window_enter_cb), desktop);
g_signal_connect (desktop->clock->window, "leave-notify-event",
G_CALLBACK (panel_window_leave_cb), desktop);
g_signal_connect (desktop->launcher_grid->window, "enter-notify-event",
G_CALLBACK (panel_window_enter_cb), desktop);
g_signal_connect (desktop->launcher_grid->window, "leave-notify-event",
G_CALLBACK (panel_window_leave_cb), desktop);
g_signal_connect (desktop->launcher_grid->window, "enter-notify-event",
G_CALLBACK (panel_window_enter_cb), desktop);
g_signal_connect (desktop->launcher_grid->window, "leave-notify-event",
G_CALLBACK (panel_window_leave_cb), desktop);
return G_SOURCE_REMOVE;
return G_SOURCE_REMOVE;
}
static void
desktop_shell_configure(void *data,
struct desktop_shell *desktop_shell,
uint32_t edges,
struct wl_surface *surface,
int32_t width, int32_t height)
desktop_shell_configure (void *data,
struct desktop_shell *desktop_shell,
uint32_t edges,
struct wl_surface *surface,
int32_t width, int32_t height)
{
struct desktop *desktop = data;
int window_height;
int grid_width, grid_height;
gtk_widget_set_size_request (desktop->background->window,
width, height);
/* TODO: make this height a little nicer */
window_height = height * MAYNARD_PANEL_HEIGHT_RATIO;
gtk_window_resize (GTK_WINDOW (desktop->panel->window),
MAYNARD_PANEL_WIDTH, window_height);
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);
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);
shell_helper_move_surface(desktop->helper,
desktop->clock->surface,
MAYNARD_PANEL_WIDTH,
(height - window_height) / 2);
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);
/* TODO: why does the panel signal leave on drawing for
* startup? we don't want to have to have this silly
* timeout. */
g_timeout_add_seconds (1, connect_enter_leave_signals, desktop);
struct desktop *desktop = data;
int window_height;
int grid_width, grid_height;
gtk_widget_set_size_request (desktop->background->window,
width, height);
/* TODO: make this height a little nicer */
window_height = height * MAYNARD_PANEL_HEIGHT_RATIO;
gtk_window_resize (GTK_WINDOW (desktop->panel->window),
MAYNARD_PANEL_WIDTH, window_height);
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);
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);
shell_helper_move_surface (desktop->helper, desktop->clock->surface,
MAYNARD_PANEL_WIDTH, (height - window_height) / 2);
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);
/* TODO: why does the panel signal leave on drawing for
* startup? we don't want to have to have this silly
* timeout. */
g_timeout_add_seconds (1, connect_enter_leave_signals, desktop);
}
static void
desktop_shell_prepare_lock_surface(void *data,
struct desktop_shell *desktop_shell)
desktop_shell_prepare_lock_surface (void *data,
struct desktop_shell *desktop_shell)
{
desktop_shell_unlock (desktop_shell);
desktop_shell_unlock (desktop_shell);
}
static void
desktop_shell_grab_cursor(void *data, struct desktop_shell *desktop_shell,
uint32_t cursor)
desktop_shell_grab_cursor (void *data,
struct desktop_shell *desktop_shell,
uint32_t cursor)
{
}
static const struct desktop_shell_listener listener = {
desktop_shell_configure,
desktop_shell_prepare_lock_surface,
desktop_shell_grab_cursor
desktop_shell_configure,
desktop_shell_prepare_lock_surface,
desktop_shell_grab_cursor
};
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,
desktop->launcher_grid->surface);
} else {
int width;
gtk_widget_get_size_request (desktop->launcher_grid->window,
&width, NULL);
shell_helper_slide_surface(desktop->helper,
desktop->launcher_grid->surface,
width + MAYNARD_PANEL_WIDTH, 0);
}
desktop->grid_visible = !desktop->grid_visible;
if (desktop->grid_visible)
{
shell_helper_slide_surface_back (desktop->helper,
desktop->launcher_grid->surface);
}
else
{
int width;
gtk_widget_get_size_request (desktop->launcher_grid->window,
&width, NULL);
shell_helper_slide_surface (desktop->helper,
desktop->launcher_grid->surface,
width + MAYNARD_PANEL_WIDTH, 0);
}
desktop->grid_visible = !desktop->grid_visible;
}
static void
launcher_grid_create (struct desktop *desktop)
{
struct element *launcher_grid;
GdkWindow *gdk_window;
struct element *launcher_grid;
GdkWindow *gdk_window;
launcher_grid = malloc (sizeof *launcher_grid);
memset (launcher_grid, 0, sizeof *launcher_grid);
launcher_grid = malloc (sizeof *launcher_grid);
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);
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_wayland_window_set_use_custom_surface(gdk_window);
shell_helper_add_surface_to_layer(desktop->helper,
launcher_grid->surface,
desktop->panel->surface);
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;
desktop->launcher_grid = launcher_grid;
}
static void
volume_changed_cb (MaynardClock *clock,
gdouble value,
const gchar *icon_name,
struct desktop *desktop)
gdouble value,
const gchar *icon_name,
struct desktop *desktop)
{
maynard_panel_set_volume_icon_name (
MAYNARD_PANEL (desktop->panel->window), icon_name);
maynard_panel_set_volume_icon_name (
MAYNARD_PANEL (desktop->panel->window), icon_name);
}
static GtkWidget *
clock_create (struct desktop *desktop)
{
struct element *clock;
GdkWindow *gdk_window;
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);
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,
desktop->panel->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);
gtk_widget_show_all (clock->window);
desktop->clock = clock;
desktop->clock = clock;
}
static void
button_toggled_cb (struct desktop *desktop,
gboolean *visible,
gboolean *not_visible)
gboolean *visible,
gboolean *not_visible)
{
*visible = !*visible;
*not_visible = FALSE;
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) {
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 {
maynard_clock_show_section (MAYNARD_CLOCK (desktop->clock->window),
MAYNARD_CLOCK_SECTION_CLOCK);
maynard_panel_show_previous (MAYNARD_PANEL (desktop->panel->window),
MAYNARD_PANEL_BUTTON_NONE);
}
*visible = !*visible;
*not_visible = FALSE;
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)
{
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
{
maynard_clock_show_section (MAYNARD_CLOCK (desktop->clock->window),
MAYNARD_CLOCK_SECTION_CLOCK);
maynard_panel_show_previous (MAYNARD_PANEL (desktop->panel->window),
MAYNARD_PANEL_BUTTON_NONE);
}
}
static void
system_toggled_cb (GtkWidget *widget,
struct desktop *desktop)
struct desktop *desktop)
{
button_toggled_cb (desktop,
&desktop->system_visible,
&desktop->volume_visible);
button_toggled_cb (desktop,
&desktop->system_visible,
&desktop->volume_visible);
}
static void
volume_toggled_cb (GtkWidget *widget,
struct desktop *desktop)
struct desktop *desktop)
{
button_toggled_cb (desktop,
&desktop->volume_visible,
&desktop->system_visible);
button_toggled_cb (desktop,
&desktop->volume_visible,
&desktop->system_visible);
}
static gboolean
panel_window_enter_cb (GtkWidget *widget,
GdkEventCrossing *event,
struct desktop *desktop)
GdkEventCrossing *event,
struct desktop *desktop)
{
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) {
g_source_remove (desktop->hide_panel_idle_id);
desktop->hide_panel_idle_id = 0;
return;
}
shell_helper_slide_surface_back(desktop->helper,
desktop->panel->surface);
shell_helper_slide_surface_back(desktop->helper,
desktop->clock->surface);
maynard_panel_set_expand(MAYNARD_PANEL(desktop->panel->window),
TRUE);
return FALSE;
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)
{
g_source_remove (desktop->hide_panel_idle_id);
desktop->hide_panel_idle_id = 0;
return;
}
shell_helper_slide_surface_back (desktop->helper,
desktop->panel->surface);
shell_helper_slide_surface_back (desktop->helper,
desktop->clock->surface);
maynard_panel_set_expand (MAYNARD_PANEL (desktop->panel->window), TRUE);
return FALSE;
}
static gboolean
leave_panel_idle_cb (gpointer data)
{
struct desktop *desktop = data;
gint width;
struct desktop *desktop = data;
gint width;
desktop->hide_panel_idle_id = 0;
desktop->hide_panel_idle_id = 0;
gtk_window_get_size (GTK_WINDOW (desktop->clock->window),
&width, NULL);
gtk_window_get_size (GTK_WINDOW (desktop->clock->window),
&width, NULL);
shell_helper_slide_surface(desktop->helper,
desktop->panel->surface,
MAYNARD_VERTICAL_CLOCK_WIDTH - MAYNARD_PANEL_WIDTH, 0);
shell_helper_slide_surface(desktop->helper,
desktop->clock->surface,
MAYNARD_VERTICAL_CLOCK_WIDTH - MAYNARD_PANEL_WIDTH - width, 0);
shell_helper_slide_surface (desktop->helper,
desktop->panel->surface,
MAYNARD_VERTICAL_CLOCK_WIDTH - MAYNARD_PANEL_WIDTH, 0);
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);
maynard_panel_show_previous (MAYNARD_PANEL (desktop->panel->window),
MAYNARD_PANEL_BUTTON_NONE);
desktop->system_visible = FALSE;
desktop->volume_visible = FALSE;
maynard_clock_show_section (MAYNARD_CLOCK (desktop->clock->window),
MAYNARD_CLOCK_SECTION_CLOCK);
maynard_panel_show_previous (MAYNARD_PANEL (desktop->panel->window),
MAYNARD_PANEL_BUTTON_NONE);
desktop->system_visible = FALSE;
desktop->volume_visible = FALSE;
return G_SOURCE_REMOVE;
return G_SOURCE_REMOVE;
}
static gboolean
panel_window_leave_cb (GtkWidget *widget,
GdkEventCrossing *event,
struct desktop *desktop)
GdkEventCrossing *event,
struct desktop *desktop)
{
if (desktop->initial_panel_timeout_id > 0) {
g_source_remove (desktop->initial_panel_timeout_id);
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)
return;
if (desktop->hide_panel_idle_id > 0)
return;
if (desktop->grid_visible)
return;
if (desktop->grid_visible)
return;
desktop->hide_panel_idle_id = g_idle_add (leave_panel_idle_cb, desktop);
desktop->hide_panel_idle_id = g_idle_add (leave_panel_idle_cb, desktop);
return FALSE;
return FALSE;
}
static gboolean
panel_hide_timeout_cb (gpointer data)
{
struct desktop *desktop = data;
struct desktop *desktop = data;
panel_window_leave_cb (NULL, NULL, desktop);
panel_window_leave_cb (NULL, NULL, desktop);
return G_SOURCE_REMOVE;
return G_SOURCE_REMOVE;
}
static void
favorite_launched_cb (MaynardPanel *panel,
struct desktop *desktop)
struct desktop *desktop)
{
if (desktop->grid_visible) {
launcher_grid_toggle (desktop->launcher_grid->window, desktop);
}
if (desktop->grid_visible)
launcher_grid_toggle (desktop->launcher_grid->window, desktop);
panel_window_leave_cb (NULL, NULL, 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;
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