Browse Source

code formatting cleanup

sisyphus
Dustin Falgout 9 years ago
parent
commit
e94fb5dd7f
  1. 215
      src/lightdm-webkit2-greeter-ext.c
  2. 106
      src/lightdm-webkit2-greeter.c

215
src/lightdm-webkit2-greeter-ext.c

@ -1,36 +1,57 @@
/*
* lightdm-webkit2-greeter-ext.c
*
* Copyright (C) 2010 Robert Ancell.
* Author: Robert Ancell <robert.ancell@canonical.com>
* Webkit2 port: Copyright (C) 2014 Antergos
* Copyright © 2014-2015 Antergos Developers <dev@antergos.com>
*
* Based on code from lightdm-webkit-greeter:
* Copyright © 2010-2015 Robert Ancell <robert.ancell@canonical.com>
*
* This file is part of lightdm-webkit2-greeter.
*
* lightdm-webkit2-greeter is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* lightdm-webkit2-greeter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* The following additional terms are in effect as per Section 7 of the license:
*
* The preservation of all legal notices and author attributions in
* the material or in the Appropriate Legal Notices displayed
* by works containing it is required.
*
* You should have received a copy of the GNU General Public License
* along with lightdm-webkit2-greeter; If not, see <http://www.gnu.org/licenses/>.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version. See http://www.gnu.org/copyleft/gpl.html the full text of the
* license.
*/
#include <stdlib.h>
#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <webkit2/webkit-web-extension.h>
#define WEBKIT_DOM_USE_UNSTABLE_API
#include <webkitdom/WebKitDOMDOMWindowUnstable.h>
#include <JavaScriptCore/JavaScript.h>
#include <glib/gi18n.h>
#include <JavaScriptCore/JavaScript.h>
#include <lightdm.h>
#include <config.h>
G_MODULE_EXPORT void
webkit_web_extension_initialize(WebKitWebExtension *extension);
G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension *extension);
guint64 page_id = -1;
static JSClassRef gettext_class;
static JSClassRef lightdm_greeter_class, lightdm_user_class, lightdm_language_class, lightdm_layout_class, lightdm_session_class;
static JSClassRef
lightdm_greeter_class,
gettext_class,
lightdm_user_class,
lightdm_language_class,
lightdm_layout_class,
lightdm_session_class;
static JSValueRef
get_user_name_cb(JSContextRef context,
@ -89,8 +110,9 @@ get_user_language_cb(JSContextRef context,
const gchar *language = lightdm_user_get_language(user);
JSStringRef string;
if (!language)
if (!language) {
return JSValueMakeNull(context);
}
string = JSStringCreateWithUTF8CString(language);
return JSValueMakeString(context, string);
@ -105,8 +127,9 @@ get_user_layout_cb(JSContextRef context,
const gchar *layout = lightdm_user_get_layout(user);
JSStringRef string;
if (!layout)
if (!layout) {
return JSValueMakeNull(context);
}
string = JSStringCreateWithUTF8CString(layout);
return JSValueMakeString(context, string);
@ -121,8 +144,9 @@ get_user_session_cb(JSContextRef context,
const gchar *session = lightdm_user_get_session(user);
JSStringRef string;
if (!session)
if (!session) {
return JSValueMakeNull(context);
}
string = JSStringCreateWithUTF8CString(session);
return JSValueMakeString(context, string);
@ -161,7 +185,6 @@ get_language_name_cb(JSContextRef context,
return JSValueMakeString(context, string);
}
static JSValueRef
get_language_territory_cb(JSContextRef context,
JSObjectRef thisObject,
@ -347,6 +370,7 @@ get_layouts_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef *exception) {
JSObjectRef array;
const GList *layouts, *link;
guint i, n_layouts = 0;
@ -371,6 +395,7 @@ get_layout_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef *exception) {
JSStringRef string;
string = JSStringCreateWithUTF8CString(lightdm_layout_get_name(lightdm_get_layout()));
@ -388,8 +413,9 @@ set_layout_cb(JSContextRef context,
char layout[1024];
// FIXME: Throw exception
if (JSValueGetType(context, value) != kJSTypeString)
if (JSValueGetType(context, value) != kJSTypeString) {
return false;
}
layout_arg = JSValueToStringCopy(context, value, NULL);
JSStringGetUTF8CString(layout_arg, layout, 1024);
@ -472,8 +498,9 @@ cancel_timed_login_cb(JSContextRef context,
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
// FIXME: Throw exception
if (argumentCount != 0)
if (argumentCount != 0) {
return JSValueMakeNull(context);
}
lightdm_greeter_cancel_autologin(greeter);
return JSValueMakeNull(context);
@ -491,8 +518,9 @@ start_authentication_cb(JSContextRef context,
char name[1024];
// FIXME: Throw exception
if (!(argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString))
if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) {
return JSValueMakeNull(context);
}
name_arg = JSValueToStringCopy(context, arguments[0], NULL);
JSStringGetUTF8CString(name_arg, name, 1024);
@ -514,8 +542,9 @@ provide_secret_cb(JSContextRef context,
char secret[1024];
// FIXME: Throw exception
if (!(argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString))
if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) {
return JSValueMakeNull(context);
}
secret_arg = JSValueToStringCopy(context, arguments[0], NULL);
JSStringGetUTF8CString(secret_arg, secret, 1024);
@ -536,8 +565,9 @@ cancel_authentication_cb(JSContextRef context,
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
// FIXME: Throw exception
if (argumentCount != 0)
if (argumentCount != 0) {
return JSValueMakeNull(context);
}
lightdm_greeter_cancel_authentication(greeter);
return JSValueMakeNull(context);
@ -577,8 +607,9 @@ suspend_cb(JSContextRef context,
const JSValueRef arguments[],
JSValueRef *exception) {
// FIXME: Throw exception
if (argumentCount != 0)
if (argumentCount != 0) {
return JSValueMakeNull(context);
}
lightdm_suspend(NULL);
return JSValueMakeNull(context);
@ -600,8 +631,9 @@ hibernate_cb(JSContextRef context,
const JSValueRef arguments[],
JSValueRef *exception) {
// FIXME: Throw exception
if (argumentCount != 0)
if (argumentCount != 0) {
return JSValueMakeNull(context);
}
lightdm_hibernate(NULL);
return JSValueMakeNull(context);
@ -623,8 +655,9 @@ restart_cb(JSContextRef context,
const JSValueRef arguments[],
JSValueRef *exception) {
// FIXME: Throw exception
if (argumentCount != 0)
if (argumentCount != 0) {
return JSValueMakeNull(context);
}
lightdm_restart(NULL);
return JSValueMakeNull(context);
@ -646,8 +679,9 @@ shutdown_cb(JSContextRef context,
const JSValueRef arguments[],
JSValueRef *exception) {
// FIXME: Throw exception
if (argumentCount != 0)
if (argumentCount != 0) {
return JSValueMakeNull(context);
}
lightdm_shutdown(NULL);
return JSValueMakeNull(context);
@ -717,8 +751,9 @@ gettext_cb(JSContextRef context,
char string[1024];
// FIXME: Throw exception
if (argumentCount != 1)
if (argumentCount != 1) {
return JSValueMakeNull(context);
}
string_arg = JSValueToStringCopy(context, arguments[0], NULL);
JSStringGetUTF8CString(string_arg, string, 1024);
@ -740,8 +775,9 @@ ngettext_cb(JSContextRef context,
unsigned int n;
// FIXME: Throw exception
if (argumentCount != 3)
if (argumentCount != 3) {
return JSValueMakeNull(context);
}
string_arg = JSValueToStringCopy(context, arguments[0], NULL);
JSStringGetUTF8CString(string_arg, string, 1024);
@ -757,8 +793,7 @@ ngettext_cb(JSContextRef context,
return JSValueMakeString(context, result);
}
static const JSStaticValue lightdm_user_values[] =
{
static const JSStaticValue lightdm_user_values[] = {
{"name", get_user_name_cb, NULL, kJSPropertyAttributeReadOnly},
{"real_name", get_user_real_name_cb, NULL, kJSPropertyAttributeReadOnly},
{"display_name", get_user_display_name_cb, NULL, kJSPropertyAttributeReadOnly},
@ -767,35 +802,27 @@ static const JSStaticValue lightdm_user_values[] =
{"layout", get_user_layout_cb, NULL, kJSPropertyAttributeReadOnly},
{"session", get_user_session_cb, NULL, kJSPropertyAttributeReadOnly},
{"logged_in", get_user_logged_in_cb, NULL, kJSPropertyAttributeReadOnly},
{NULL, NULL, NULL, 0}
};
{NULL, NULL, NULL, 0}};
static const JSStaticValue lightdm_language_values[] =
{
static const JSStaticValue lightdm_language_values[] = {
{"code", get_language_code_cb, NULL, kJSPropertyAttributeReadOnly},
{"name", get_language_name_cb, NULL, kJSPropertyAttributeReadOnly},
{"territory", get_language_territory_cb, NULL, kJSPropertyAttributeReadOnly},
{NULL, NULL, NULL, 0}
};
{NULL, NULL, NULL, 0}};
static const JSStaticValue lightdm_layout_values[] =
{
static const JSStaticValue lightdm_layout_values[] = {
{"name", get_layout_name_cb, NULL, kJSPropertyAttributeReadOnly},
{"short_description", get_layout_short_description_cb, NULL, kJSPropertyAttributeReadOnly},
{"description", get_layout_description_cb, NULL, kJSPropertyAttributeReadOnly},
{NULL, NULL, NULL, 0}
};
{NULL, NULL, NULL, 0}};
static const JSStaticValue lightdm_session_values[] =
{
static const JSStaticValue lightdm_session_values[] = {
{"key", get_session_key_cb, NULL, kJSPropertyAttributeReadOnly},
{"name", get_session_name_cb, NULL, kJSPropertyAttributeReadOnly},
{"comment", get_session_comment_cb, NULL, kJSPropertyAttributeReadOnly},
{NULL, NULL, NULL, 0}
};
{NULL, NULL, NULL, 0}};
static const JSStaticValue lightdm_greeter_values[] =
{
static const JSStaticValue lightdm_greeter_values[] = {
{"hostname", get_hostname_cb, NULL, kJSPropertyAttributeReadOnly},
{"users", get_users_cb, NULL, kJSPropertyAttributeReadOnly},
{"default_language", get_default_language_cb, NULL, kJSPropertyAttributeReadOnly},
@ -814,11 +841,9 @@ static const JSStaticValue lightdm_greeter_values[] =
{"can_hibernate", get_can_hibernate_cb, NULL, kJSPropertyAttributeReadOnly},
{"can_restart", get_can_restart_cb, NULL, kJSPropertyAttributeReadOnly},
{"can_shutdown", get_can_shutdown_cb, NULL, kJSPropertyAttributeReadOnly},
{NULL, NULL, NULL, 0}
};
{NULL, NULL, NULL, 0}};
static const JSStaticFunction lightdm_greeter_functions[] =
{
static const JSStaticFunction lightdm_greeter_functions[] = {
{"cancel_timed_login", cancel_timed_login_cb, kJSPropertyAttributeReadOnly},
{"start_authentication", start_authentication_cb, kJSPropertyAttributeReadOnly},
{"provide_secret", provide_secret_cb, kJSPropertyAttributeReadOnly},
@ -828,19 +853,14 @@ static const JSStaticFunction lightdm_greeter_functions[] =
{"restart", restart_cb, kJSPropertyAttributeReadOnly},
{"shutdown", shutdown_cb, kJSPropertyAttributeReadOnly},
{"set_language", set_language_cb, kJSPropertyAttributeReadOnly},
{"login", login_cb, kJSPropertyAttributeReadOnly},
{NULL, NULL, 0}
};
{"login", login_cb, kJSPropertyAttributeReadOnly}, {NULL, NULL, 0}};
static const JSStaticFunction gettext_functions[] =
{
static const JSStaticFunction gettext_functions[] = {
{"gettext", gettext_cb, kJSPropertyAttributeReadOnly},
{"ngettext", ngettext_cb, kJSPropertyAttributeReadOnly},
{NULL, NULL, 0}
};
{NULL, NULL, 0}};
static const JSClassDefinition lightdm_user_definition =
{
static const JSClassDefinition lightdm_user_definition = {
0, /* Version */
kJSClassAttributeNone, /* Attributes */
"LightDMUser", /* Class name */
@ -848,8 +868,7 @@ static const JSClassDefinition lightdm_user_definition =
lightdm_user_values, /* Static values */
};
static const JSClassDefinition lightdm_language_definition =
{
static const JSClassDefinition lightdm_language_definition = {
0, /* Version */
kJSClassAttributeNone, /* Attributes */
"LightDMLanguage", /* Class name */
@ -857,8 +876,7 @@ static const JSClassDefinition lightdm_language_definition =
lightdm_language_values, /* Static values */
};
static const JSClassDefinition lightdm_layout_definition =
{
static const JSClassDefinition lightdm_layout_definition = {
0, /* Version */
kJSClassAttributeNone, /* Attributes */
"LightDMLayout", /* Class name */
@ -866,8 +884,7 @@ static const JSClassDefinition lightdm_layout_definition =
lightdm_layout_values, /* Static values */
};
static const JSClassDefinition lightdm_session_definition =
{
static const JSClassDefinition lightdm_session_definition = {
0, /* Version */
kJSClassAttributeNone, /* Attributes */
"LightDMSession", /* Class name */
@ -875,8 +892,7 @@ static const JSClassDefinition lightdm_session_definition =
lightdm_session_values, /* Static values */
};
static const JSClassDefinition lightdm_greeter_definition =
{
static const JSClassDefinition lightdm_greeter_definition = {
0, /* Version */
kJSClassAttributeNone, /* Attributes */
"LightDMGreeter", /* Class name */
@ -885,25 +901,23 @@ static const JSClassDefinition lightdm_greeter_definition =
lightdm_greeter_functions, /* Static functions */
};
static const JSClassDefinition gettext_definition =
{
static const JSClassDefinition gettext_definition = {
0, /* Version */
kJSClassAttributeNone, /* Attributes */
"GettextClass", /* Class name */
NULL, /* Parent class */
NULL,
NULL, /* Static values */
gettext_functions, /* Static functions */
};
static void
web_page_created_callback(WebKitWebExtension *extension,
WebKitWebPage *web_page,
gpointer user_data) {
/* guint64 page_id = webkit_web_page_get_id (web_page); */
web_page_created_callback(WebKitWebExtension *extension, WebKitWebPage *web_page, gpointer user_data) {
/*@formatter:off*/
g_print("Page %" G_GUINT64_FORMAT "created for %s\n",
webkit_web_page_get_id(web_page),
webkit_web_page_get_uri(web_page));
webkit_web_page_get_uri(web_page)
);
/*@formatter:on*/
}
static void
@ -929,21 +943,21 @@ window_object_cleared_callback(WebKitScriptWorld *world,
gettext_object = JSObjectMake(jsContext, gettext_class, NULL);
JSObjectSetProperty(jsContext,
globalObject,
JSStringCreateWithUTF8CString("gettext"),
gettext_object, kJSPropertyAttributeNone, NULL);
JSObjectSetProperty(jsContext, globalObject, JSStringCreateWithUTF8CString("gettext"), gettext_object,
kJSPropertyAttributeNone, NULL);
lightdm_greeter_object = JSObjectMake(jsContext, lightdm_greeter_class, greeter);
JSObjectSetProperty(jsContext,
globalObject,
JSStringCreateWithUTF8CString("lightdm"),
lightdm_greeter_object, kJSPropertyAttributeNone, NULL);
JSObjectSetProperty(jsContext, globalObject, JSStringCreateWithUTF8CString("lightdm"), lightdm_greeter_object,
kJSPropertyAttributeNone, NULL);
}
static void
show_prompt_cb(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, WebKitWebExtension *extension) {
show_prompt_cb(LightDMGreeter *greeter,
const gchar *text,
LightDMPromptType type,
WebKitWebExtension *extension) {
WebKitWebPage *web_page;
WebKitFrame *web_frame;
JSGlobalContextRef jsContext;
@ -969,7 +983,11 @@ show_prompt_cb(LightDMGreeter *greeter, const gchar *text, LightDMPromptType typ
}
static void
show_message_cb(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, WebKitWebExtension *extension) {
show_message_cb(LightDMGreeter *greeter,
const gchar *text,
LightDMMessageType type,
WebKitWebExtension *extension) {
WebKitWebPage *web_page;
WebKitFrame *web_frame;
JSGlobalContextRef jsContext;
@ -993,6 +1011,7 @@ show_message_cb(LightDMGreeter *greeter, const gchar *text, LightDMMessageType t
static void
authentication_complete_cb(LightDMGreeter *greeter, WebKitWebExtension *extension) {
WebKitWebPage *web_page;
WebKitFrame *web_frame;
JSGlobalContextRef jsContext;
@ -1011,7 +1030,7 @@ authentication_complete_cb(LightDMGreeter *greeter, WebKitWebExtension *extensio
}
}
/*static gboolean
static gboolean
fade_timer_cb(gpointer data) {
gdouble opacity;
@ -1031,7 +1050,8 @@ quit_cb(LightDMGreeter *greeter, const gchar *username) {
// Fade out the greeter
g_timeout_add(40, (GSourceFunc) fade_timer_cb, NULL);
}*/
}
G_MODULE_EXPORT void
webkit_web_extension_initialize(WebKitWebExtension *extension) {
@ -1042,14 +1062,15 @@ webkit_web_extension_initialize(WebKitWebExtension *extension) {
g_signal_connect(G_OBJECT(greeter), "authentication-complete", G_CALLBACK(authentication_complete_cb), extension);
g_signal_connect(G_OBJECT(greeter), "show-prompt", G_CALLBACK(show_prompt_cb), extension);
g_signal_connect(G_OBJECT(greeter), "show-message", G_CALLBACK(show_message_cb), extension);
// g_signal_connect(G_OBJECT(greeter), "quit", G_CALLBACK(quit_cb), extension);
g_signal_connect(extension, "page-created", G_CALLBACK(web_page_created_callback), NULL);
/* TODO: Find the best way to send quit signal to the main window from our web-extension (probably dbus).
* g_signal_connect(G_OBJECT(greeter), "quit", G_CALLBACK(quit_cb), extension);
*/
/* g_signal_connect(extension, "page-created", G_CALLBACK(web_page_created_callback), NULL); */
g_signal_connect(webkit_script_world_get_default(),
"window-object-cleared",
G_CALLBACK(window_object_cleared_callback),
greeter);
g_signal_connect(webkit_script_world_get_default(), "window-object-cleared",
G_CALLBACK(window_object_cleared_callback), greeter);
lightdm_greeter_connect_sync(greeter, NULL);
}

106
src/lightdm-webkit2-greeter.c

@ -1,15 +1,32 @@
/*
* lightdm-webkit2-greeter.c
*
* Copyright (C) 2010 Robert Ancell.
* Author: Robert Ancell <robert.ancell@canonical.com>
* Webkit2 port: Copyright (C) 2014 Antergos
* Copyright © 2014-2015 Antergos Developers <dev@antergos.com>
*
* Based on code from lightdm-webkit-greeter:
* Copyright © 2010-2015 Robert Ancell <robert.ancell@canonical.com>
*
* This file is part of lightdm-webkit2-greeter.
*
* lightdm-webkit2-greeter is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* lightdm-webkit2-greeter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* The following additional terms are in effect as per Section 7 of the license:
*
* The preservation of all legal notices and author attributions in
* the material or in the Appropriate Legal Notices displayed
* by works containing it is required.
*
* You should have received a copy of the GNU General Public License
* along with lightdm-webkit2-greeter; If not, see <http://www.gnu.org/licenses/>.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version. See http://www.gnu.org/copyleft/gpl.html the full text of the
* license.
*/
#include <stdlib.h>
@ -30,17 +47,6 @@ static GtkWidget *web_view;
static GtkWidget *window;
static WebKitSettings *webkit_settings;
/*
static void
timed_login_cb (LightDMGreeter *greeter, const gchar *username, WebKitWebView *view)
{
gchar *command;
command = g_strdup_printf ("timed_login('%s')", username); // FIXME: Escape text
webkit_web_view_run_javascript (view, command, NULL, web_view_javascript_finished, NULL);
g_free (command);
}*/
static void
sigterm_cb(int signum) {
@ -49,36 +55,34 @@ sigterm_cb(int signum) {
static GdkFilterReturn
wm_window_filter(GdkXEvent *gxevent, GdkEvent *event, gpointer data) {
XEvent *xevent = (XEvent *) gxevent;
if (xevent->type == MapNotify) {
GdkDisplay *display = gdk_x11_lookup_xdisplay(xevent->xmap.display);
GdkWindow *win = gdk_x11_window_foreign_new_for_display(display, xevent->xmap.window);
GdkWindowTypeHint win_type = gdk_window_get_type_hint(win);
if (win_type != GDK_WINDOW_TYPE_HINT_COMBO &&
win_type != GDK_WINDOW_TYPE_HINT_TOOLTIP &&
win_type != GDK_WINDOW_TYPE_HINT_NOTIFICATION)
/*
if (win_type == GDK_WINDOW_TYPE_HINT_DESKTOP ||
win_type == GDK_WINDOW_TYPE_HINT_DIALOG)
*/
if (win_type != GDK_WINDOW_TYPE_HINT_COMBO && win_type != GDK_WINDOW_TYPE_HINT_TOOLTIP
&& win_type != GDK_WINDOW_TYPE_HINT_NOTIFICATION) {
gdk_window_focus(win, GDK_CURRENT_TIME);
}
else if (xevent->type == UnmapNotify) {
} else if (xevent->type == UnmapNotify) {
Window xwin;
int revert_to = RevertToNone;
XGetInputFocus(xevent->xunmap.display, &xwin, &revert_to);
if (revert_to == RevertToNone)
if (revert_to == RevertToNone) {
gdk_window_lower(gtk_widget_get_window(gtk_widget_get_toplevel(GTK_WIDGET(window))));
}
}
return GDK_FILTER_CONTINUE;
}
static void
initialize_web_extensions_cb(WebKitWebContext *context,
gpointer user_data) {
initialize_web_extensions_cb(WebKitWebContext *context, gpointer user_data) {
webkit_web_context_set_web_extensions_directory(context, LIGHTDM_WEBKIT2_GREETER_EXTENSIONS_DIR);
@ -86,7 +90,8 @@ initialize_web_extensions_cb(WebKitWebContext *context,
static void
create_new_webkit_settings_object(void) {
webkit_settings = webkit_settings_new_with_settings("enable-developer-extras", TRUE,
webkit_settings = webkit_settings_new_with_settings(
"enable-developer-extras", FALSE,
"enable-fullscreen", TRUE,
"enable-site-specific-quirks", TRUE,
"enable-dns-prefetching", TRUE,
@ -96,13 +101,23 @@ create_new_webkit_settings_object(void) {
"enable-smooth-scrolling", TRUE,
"enable-webgl", TRUE,
"enable-write-console-messages-to-stdout", TRUE,
NULL
);
}
NULL);
static gboolean
context_menu_cb(WebKitWebView *web_view,
WebKitContextMenu *context_menu,
GdkEvent *event,
WebKitHitTestResult *hit_test_result,
gpointer user_data) {
return TRUE;
}
int
main(int argc, char **argv) {
GdkScreen *screen;
GdkWindow *root_window;
GdkRectangle geometry;
GKeyFile *keyfile;
gchar *theme;
@ -113,42 +128,43 @@ main(int argc, char **argv) {
gtk_init(&argc, &argv);
WebKitWebContext *context = webkit_web_context_get_default();
g_signal_connect(context,
"initialize-web-extensions",
G_CALLBACK(initialize_web_extensions_cb),
NULL);
gdk_window_set_cursor(gdk_get_default_root_window(),
gdk_cursor_new_for_display(gdk_display_get_default(), GDK_LEFT_PTR));
g_signal_connect(context, "initialize-web-extensions", G_CALLBACK(initialize_web_extensions_cb), NULL);
/* settings */
// Apply greeter settings from conf file
keyfile = g_key_file_new();
g_key_file_load_from_file(keyfile, "/etc/lightdm/lightdm-webkit2-greeter.conf", G_KEY_FILE_NONE, NULL);
theme = g_key_file_get_string(keyfile, "greeter", "webkit-theme", NULL);
// Setup the main window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
screen = gtk_window_get_screen(GTK_WINDOW(window));
root_window = gdk_get_default_root_window();
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
gdk_screen_get_monitor_geometry(screen, gdk_screen_get_primary_monitor(screen), &geometry);
gtk_window_set_default_size(GTK_WINDOW(window), geometry.width, geometry.height);
gtk_window_move(GTK_WINDOW(window), geometry.x, geometry.y);
gdk_window_set_cursor(root_window, gdk_cursor_new_for_display(gdk_display_get_default(), GDK_LEFT_PTR));
// There is no window manager, so we need to implement some of its functionality
gdk_window_set_events(root_window, gdk_window_get_events(root_window) | GDK_SUBSTRUCTURE_MASK);
gdk_window_add_filter(root_window, wm_window_filter, NULL);
// Configure the web_view's settings.
create_new_webkit_settings_object();
web_view = webkit_web_view_new_with_settings(webkit_settings);
// The default background is white which causes a flash effect when the greeter starts. Make it black instead.
gdk_rgba_parse(&bg_color, "#000000");
webkit_web_view_set_background_color(WEBKIT_WEB_VIEW(web_view), gdk_rgba_copy(&bg_color));
gtk_container_add(GTK_CONTAINER(window), web_view);
// Disable the context (right-click) menu.
g_signal_connect(web_view, "context-menu", G_CALLBACK(context_menu_cb), NULL);
gtk_container_add(GTK_CONTAINER(window), web_view);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view), g_strdup_printf("file://%s/%s/index.html", THEME_DIR, theme));
/* There is no window manager, so we need to implement some of its functionality */
GdkWindow *root_window = gdk_get_default_root_window();
gdk_window_set_events(root_window, gdk_window_get_events(root_window) | GDK_SUBSTRUCTURE_MASK);
gdk_window_add_filter(root_window, wm_window_filter, NULL);
gtk_widget_show_all(window);

Loading…
Cancel
Save