Browse Source

code formatting tweaks

sisyphus
Dustin Falgout 9 years ago
parent
commit
dbe18f517e
  1. 173
      src/lightdm-webkit2-greeter-ext.c
  2. 14
      src/lightdm-webkit2-greeter.c

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

@ -63,13 +63,12 @@ static JSClassRef
/*
* string_or_null.
* Returns either a string or null.
*
* When passed a const gchar string, either return a JSValueRef string, or a
* JSValueRef Null reference if the string is NULL. Used to ensure functions
* When passed a const gchar string, either return a JSValueRef string or,
* if the string is NULL, a JSValueRef Null reference. Used to ensure functions
* return proper string args.
*/
static JSValueRef
string_or_null(JSContextRef context, const gchar *str) {
JSValueRef result;
@ -86,12 +85,12 @@ string_or_null(JSContextRef context, const gchar *str) {
return result;
}
/*
* mkexception
* Makes an Exception.
*
* Convert a const string to an exception which can be passed back to webkit.
*/
static void
_mkexception(JSContextRef context, JSValueRef *exception, const gchar *str) {
JSValueRef result;
@ -99,23 +98,27 @@ _mkexception (JSContextRef context, JSValueRef * exception, const gchar * str) {
JSValueRef exceptionString = JSValueMakeString(context, string);
JSStringRelease(string);
result = JSValueToObject(context, exceptionString, exception);
if (result != NULL)
if (result != NULL) {
*exception = result;
}
}
static JSValueRef
mkexception(JSContextRef context, JSValueRef *exception, const gchar *str) {
_mkexception(context, exception, str);
return JSValueMakeNull(context);
}
/*
* arg_to_string
* Converts an argument to a string.
*
* Convert an JSValueRef argument to a g_malloc'd gchar string. Calling function
* Convert a JSValueRef argument to a g_malloc'd gchar string. Calling function
* is responsible for g_freeing the string.
*/
static gchar *
arg_to_string(JSContextRef context, JSValueRef arg, JSValueRef *exception) {
JSStringRef string;
@ -124,29 +127,38 @@ arg_to_string (JSContextRef context, JSValueRef arg, JSValueRef * exception) {
if (JSValueGetType(context, arg) != kJSTypeString) {
_mkexception(context, exception, "Expected a string");
return NULL;
}
string = JSValueToStringCopy(context, arg, exception);
if (!string)
if (!string) {
return NULL;
}
size = JSStringGetMaximumUTF8CStringSize(string);
result = g_malloc(size);
if (!result)
if (!result) {
return NULL;
}
JSStringGetUTF8CString(string, result, size);
JSStringRelease(string);
return result;
}
/*
* escape
* Escapes single quote characters in a string.
*
* Simple escape function to make sure strings have any single quote characters
* escaped.
* Simple escape function to make sure strings have any/all single
* quote characters escaped.
*/
static char *
escape(const gchar *text) {
size_t len;
@ -163,12 +175,14 @@ escape(const gchar *text) {
}
if (count == 0) {
return g_strdup(text);
}
escaped = g_malloc(len + count + 1);
j = 0;
for (i = 0; i <= len; i++) {
if (text[i] == '\'') {
escaped[j] = '\\';
@ -358,7 +372,10 @@ get_num_users_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef *exception) {
return JSValueMakeNumber(context, g_list_length(lightdm_user_list_get_users(lightdm_user_list_get_instance())));
return JSValueMakeNumber(
context,
g_list_length(lightdm_user_list_get_users(lightdm_user_list_get_instance()))
);
}
@ -367,6 +384,7 @@ get_users_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef *exception) {
JSObjectRef array;
const GList *users, *link;
guint i, n_users = 0;
@ -384,11 +402,13 @@ get_users_cb(JSContextRef context,
array = JSObjectMakeArray(context, n_users, args, exception);
g_free(args);
if (array == NULL)
if (array == NULL) {
return JSValueMakeNull(context);
else
} else {
return array;
}
}
static JSValueRef
@ -396,6 +416,7 @@ get_languages_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef *exception) {
JSObjectRef array;
const GList *languages, *link;
guint i, n_languages = 0;
@ -413,11 +434,13 @@ get_languages_cb(JSContextRef context,
array = JSObjectMakeArray(context, n_languages, args, exception);
g_free(args);
if (array == NULL)
if (array == NULL) {
return JSValueMakeNull(context);
else
} else {
return array;
}
}
static JSValueRef
@ -452,11 +475,13 @@ get_layouts_cb(JSContextRef context,
array = JSObjectMakeArray(context, n_layouts, args, exception);
g_free(args);
if (array == NULL)
if (array == NULL) {
return JSValueMakeNull(context);
else
} else {
return array;
}
}
static JSValueRef
@ -474,12 +499,14 @@ set_layout_cb(JSContextRef context,
JSStringRef propertyName,
JSValueRef value,
JSValueRef *exception) {
gchar *layout;
const GList *layouts, *link;
layout = arg_to_string(context, value, exception);
if (!layout)
if (!layout) {
return false;
}
layouts = lightdm_get_layouts();
@ -494,6 +521,7 @@ set_layout_cb(JSContextRef context,
}
g_free(layout);
return true;
}
@ -503,6 +531,7 @@ get_sessions_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef *exception) {
JSObjectRef array;
const GList *sessions, *link;
guint i, n_sessions = 0;
@ -521,11 +550,13 @@ get_sessions_cb(JSContextRef context,
array = JSObjectMakeArray(context, n_sessions, args, exception);
g_free(args);
if (array == NULL)
if (array == NULL) {
return JSValueMakeNull(context);
else
} else {
return array;
}
}
static JSValueRef
@ -562,7 +593,9 @@ cancel_autologin_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
lightdm_greeter_cancel_autologin(GREETER);
return JSValueMakeNull(context);
}
@ -574,14 +607,16 @@ authenticate_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
gchar *name = NULL;
if (argumentCount > 0)
if (argumentCount > 0) {
name = arg_to_string(context, arguments[0], exception);
}
lightdm_greeter_authenticate(GREETER, name);
g_free(name);
return JSValueMakeNull(context);
}
@ -593,7 +628,9 @@ authenticate_as_guest_cb (JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
lightdm_greeter_authenticate_as_guest(GREETER);
return JSValueMakeNull(context);
}
@ -605,15 +642,19 @@ get_hint_cb (JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
gchar *hint_name;
JSValueRef result;
if (argumentCount != 1)
if (argumentCount != 1) {
return mkexception(context, exception, "Hint argument not supplied");
}
hint_name = arg_to_string(context, arguments[0], exception);
if (!hint_name)
if (!hint_name) {
return JSValueMakeNull(context);
}
result = string_or_null(context, lightdm_greeter_get_hint(GREETER, hint_name));
g_free(hint_name);
@ -629,18 +670,22 @@ respond_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
gchar *response;
if (argumentCount != 1)
if (argumentCount != 1) {
return mkexception(context, exception, "Response not supplied");
}
response = arg_to_string(context, arguments[0], exception);
if (!response)
if (!response) {
return JSValueMakeNull(context);
}
lightdm_greeter_respond(GREETER, response);
g_free(response);
return JSValueMakeNull(context);
}
@ -652,7 +697,9 @@ cancel_authentication_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
lightdm_greeter_cancel_authentication(GREETER);
return JSValueMakeNull(context);
}
@ -755,6 +802,7 @@ suspend_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
lightdm_suspend(NULL);
return JSValueMakeNull(context);
@ -778,6 +826,7 @@ hibernate_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
lightdm_hibernate(NULL);
return JSValueMakeNull(context);
@ -801,6 +850,7 @@ restart_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
lightdm_restart(NULL);
return JSValueMakeNull(context);
@ -824,6 +874,7 @@ shutdown_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
lightdm_shutdown(NULL);
return JSValueMakeNull(context);
@ -837,6 +888,7 @@ start_session_sync_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
gchar *session = NULL;
gboolean result;
GError *err = NULL;
@ -845,20 +897,20 @@ start_session_sync_cb(JSContextRef context,
* is never actually used. At some point, deprecate the old usage. For now,
* simply work around it. */
if (argumentCount == 1)
if (argumentCount == 1) {
session = arg_to_string(context, arguments[0], exception);
else if (argumentCount == 2)
} else if (argumentCount == 2) {
session = arg_to_string(context, arguments[1], exception);
else if (argumentCount == 0)
} else if (argumentCount == 0) {
session = NULL;
else {
} else {
_mkexception(context, exception, "Incorrect parameters");
return JSValueMakeBoolean(context, FALSE);
}
result = lightdm_greeter_start_session_sync(GREETER, session, &err);
g_free(session);
if (err != NULL) {
_mkexception(context, exception, err->message);
g_error_free(err);
@ -875,18 +927,23 @@ set_language_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
gchar *language;
if (argumentCount != 1)
if (argumentCount != 1) {
return mkexception(context, exception, "Language not supplied");
}
language = arg_to_string(context, arguments[0], exception);
if (!language)
if (!language) {
return JSValueMakeNull(context);
}
lightdm_greeter_set_language(GREETER, language);
g_free(language);
return JSValueMakeNull(context);
}
@ -898,15 +955,20 @@ gettext_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
gchar *string;
JSValueRef result;
if (argumentCount != 1)
if (argumentCount != 1) {
return mkexception(context, exception, "Argument not supplied");
}
string = arg_to_string(context, arguments[0], exception);
if (!string)
if (!string) {
return JSValueMakeNull(context);
}
result = string_or_null(context, gettext(string));
g_free(string);
@ -921,6 +983,7 @@ ngettext_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
gchar *string, *plural_string;
unsigned int n;
JSValueRef result;
@ -930,14 +993,20 @@ ngettext_cb(JSContextRef context,
}
string = arg_to_string(context, arguments[0], exception);
if (!string)
if (!string) {
return JSValueMakeNull(context);
}
plural_string = arg_to_string(context, arguments[1], exception);
if (!plural_string)
if (!plural_string) {
return JSValueMakeNull(context);
n = JSValueToNumber (context, arguments[2], exception);
}
n = JSValueToNumber(context, arguments[2], exception);
result = string_or_null(context, ngettext(string, plural_string, n));
g_free(string);
g_free(plural_string);
@ -1117,6 +1186,7 @@ window_object_cleared_callback(WebKitScriptWorld *world,
lightdm_session_class = JSClassCreate(&lightdm_session_definition);
gettext_object = JSObjectMake(jsContext, gettext_class, NULL);
JSObjectSetProperty(jsContext,
globalObject,
JSStringCreateWithUTF8CString("gettext"),
@ -1125,6 +1195,7 @@ window_object_cleared_callback(WebKitScriptWorld *world,
NULL);
lightdm_greeter_object = JSObjectMake(jsContext, lightdm_greeter_class, greeter);
JSObjectSetProperty(jsContext,
globalObject,
JSStringCreateWithUTF8CString("lightdm"),
@ -1228,8 +1299,7 @@ show_message_cb(LightDMGreeter *greeter,
static void
authentication_complete_cb(LightDMGreeter *greeter,
WebKitWebExtension *extension) {
authentication_complete_cb(LightDMGreeter *greeter, WebKitWebExtension *extension) {
WebKitWebPage *web_page;
WebKitFrame *web_frame;
@ -1240,9 +1310,7 @@ authentication_complete_cb(LightDMGreeter *greeter,
if (web_page != NULL) {
web_frame = webkit_web_page_get_main_frame(web_page);
jsContext = webkit_frame_get_javascript_global_context(web_frame);
command = JSStringCreateWithUTF8CString("authentication_complete()");
JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL);
@ -1251,8 +1319,7 @@ authentication_complete_cb(LightDMGreeter *greeter,
static void
autologin_timer_expired_cb(LightDMGreeter *greeter,
WebKitWebExtension *extension) {
autologin_timer_expired_cb(LightDMGreeter *greeter, WebKitWebExtension *extension) {
WebKitWebPage *web_page;
WebKitFrame *web_frame;
@ -1263,9 +1330,7 @@ autologin_timer_expired_cb(LightDMGreeter *greeter,
if (web_page != NULL) {
web_frame = webkit_web_page_get_main_frame(web_page);
jsContext = webkit_frame_get_javascript_global_context(web_frame);
command = JSStringCreateWithUTF8CString("autologin_timer_expired()");
JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL);

14
src/lightdm-webkit2-greeter.c

@ -1,7 +1,7 @@
/*
* lightdm-webkit2-greeter.c
*
* Copyright © 2014-2015 Antergos Developers <dev@antergos.com>
* Copyright © 2014-2016 Antergos Developers <dev@antergos.com>
*
* Based on code from lightdm-webkit-greeter:
* Copyright © 2010-2015 Robert Ancell <robert.ancell@canonical.com>
@ -57,8 +57,8 @@ static gint config_timeout;
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);
@ -117,14 +117,16 @@ context_menu_cb(WebKitWebView *view,
GdkEvent *event,
WebKitHitTestResult *hit_test_result,
gpointer user_data) {
return TRUE;
}
static void
greeter_bridge_lock_hint_cb(void) {
// Make the greeter behave a bit more like a screensaver if used as un/lock-screen by blanking the screen.
// Make the greeter behave a bit more like a screensaver if used as [un]lock-screen by blanking the screen.
Display *display = gdk_x11_display_get_xdisplay(default_display);
XGetScreenSaver(display, &timeout, &interval, &prefer_blanking, &allow_exposures);
XForceScreenSaver(display, ScreenSaverActive);
XSetScreenSaver(display,
@ -141,7 +143,8 @@ message_received_cb(WebKitUserContentManager *manager,
gpointer user_data) {
/* TODO:
* Abstract this by using JSON for exchanging messages so the handler can be used for more than one task/event.
* Abstract this by using JSON for exchanging messages so the handler can
* be used for more than one task/event.
*/
greeter_bridge_lock_hint_cb();
@ -151,13 +154,14 @@ message_received_cb(WebKitUserContentManager *manager,
static gboolean
fade_timer_cb(gpointer data) {
gdouble opacity;
opacity = gtk_widget_get_opacity(web_view);
opacity -= 0.1;
if (opacity <= 0) {
gtk_main_quit();
return FALSE;
}
gtk_widget_set_opacity(web_view, opacity);
return TRUE;

Loading…
Cancel
Save