Browse Source

code formatting tweaks

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

437
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 * When passed a const gchar string, either return a JSValueRef string or,
* JSValueRef Null reference if the string is NULL. Used to ensure functions * if the string is NULL, a JSValueRef Null reference. Used to ensure functions
* return proper string args. * return proper string args.
*/ */
static JSValueRef static JSValueRef
string_or_null(JSContextRef context, const gchar *str) { string_or_null(JSContextRef context, const gchar *str) {
JSValueRef result; JSValueRef result;
@ -86,67 +85,80 @@ string_or_null(JSContextRef context, const gchar *str) {
return result; return result;
} }
/* /*
* mkexception * Makes an Exception.
* *
* Convert a const string to an exception which can be passed back to webkit. * Convert a const string to an exception which can be passed back to webkit.
*/ */
static void static void
_mkexception (JSContextRef context, JSValueRef * exception, const gchar * str) { _mkexception(JSContextRef context, JSValueRef *exception, const gchar *str) {
JSValueRef result; JSValueRef result;
JSStringRef string = JSStringCreateWithUTF8CString (str); JSStringRef string = JSStringCreateWithUTF8CString(str);
JSValueRef exceptionString = JSValueMakeString (context, string); JSValueRef exceptionString = JSValueMakeString(context, string);
JSStringRelease (string); JSStringRelease(string);
result = JSValueToObject (context, exceptionString, exception); result = JSValueToObject(context, exceptionString, exception);
if (result != NULL)
if (result != NULL) {
*exception = result; *exception = result;
}
} }
static JSValueRef static JSValueRef
mkexception (JSContextRef context, JSValueRef * exception, const gchar * str) { mkexception(JSContextRef context, JSValueRef *exception, const gchar *str) {
_mkexception (context, exception, str); _mkexception(context, exception, str);
return JSValueMakeNull (context);
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. * is responsible for g_freeing the string.
*/ */
static gchar * static gchar *
arg_to_string (JSContextRef context, JSValueRef arg, JSValueRef * exception) { arg_to_string(JSContextRef context, JSValueRef arg, JSValueRef *exception) {
JSStringRef string; JSStringRef string;
size_t size; size_t size;
gchar *result; gchar *result;
if (JSValueGetType(context, arg) != kJSTypeString) {
_mkexception(context, exception, "Expected a string");
if (JSValueGetType (context, arg) != kJSTypeString) {
_mkexception (context, exception, "Expected a string");
return NULL; return NULL;
} }
string = JSValueToStringCopy (context, arg, exception); string = JSValueToStringCopy(context, arg, exception);
if (!string)
if (!string) {
return NULL; return NULL;
size = JSStringGetMaximumUTF8CStringSize (string); }
result = g_malloc (size);
if (!result) size = JSStringGetMaximumUTF8CStringSize(string);
result = g_malloc(size);
if (!result) {
return NULL; return NULL;
JSStringGetUTF8CString (string, result, size); }
JSStringRelease (string);
JSStringGetUTF8CString(string, result, size);
JSStringRelease(string);
return result; return result;
} }
/* /*
* escape * Escapes single quote characters in a string.
* *
* Simple escape function to make sure strings have any single quote characters * Simple escape function to make sure strings have any/all single
* escaped. * quote characters escaped.
*/ */
static char * static char *
escape(const gchar *text) { escape(const gchar *text) {
size_t len; size_t len;
@ -163,12 +175,14 @@ escape(const gchar *text) {
} }
if (count == 0) { if (count == 0) {
return g_strdup(text); return g_strdup(text);
} }
escaped = g_malloc(len + count + 1); escaped = g_malloc(len + count + 1);
j = 0; j = 0;
for (i = 0; i <= len; i++) { for (i = 0; i <= len; i++) {
if (text[i] == '\'') { if (text[i] == '\'') {
escaped[j] = '\\'; escaped[j] = '\\';
@ -211,9 +225,9 @@ get_user_display_name_cb(JSContextRef context,
static JSValueRef static JSValueRef
get_user_home_directory_cb(JSContextRef context, get_user_home_directory_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef *exception) { JSValueRef *exception) {
return string_or_null(context, lightdm_user_get_home_directory(USER)); return string_or_null(context, lightdm_user_get_home_directory(USER));
} }
@ -358,7 +372,10 @@ get_num_users_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef *exception) { 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, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef *exception) { JSValueRef *exception) {
JSObjectRef array; JSObjectRef array;
const GList *users, *link; const GList *users, *link;
guint i, n_users = 0; guint i, n_users = 0;
@ -384,10 +402,12 @@ get_users_cb(JSContextRef context,
array = JSObjectMakeArray(context, n_users, args, exception); array = JSObjectMakeArray(context, n_users, args, exception);
g_free(args); g_free(args);
if (array == NULL)
return JSValueMakeNull (context); if (array == NULL) {
else return JSValueMakeNull(context);
} else {
return array; return array;
}
} }
@ -396,6 +416,7 @@ get_languages_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef *exception) { JSValueRef *exception) {
JSObjectRef array; JSObjectRef array;
const GList *languages, *link; const GList *languages, *link;
guint i, n_languages = 0; guint i, n_languages = 0;
@ -413,10 +434,12 @@ get_languages_cb(JSContextRef context,
array = JSObjectMakeArray(context, n_languages, args, exception); array = JSObjectMakeArray(context, n_languages, args, exception);
g_free(args); g_free(args);
if (array == NULL)
return JSValueMakeNull (context); if (array == NULL) {
else return JSValueMakeNull(context);
} else {
return array; return array;
}
} }
@ -452,10 +475,12 @@ get_layouts_cb(JSContextRef context,
array = JSObjectMakeArray(context, n_layouts, args, exception); array = JSObjectMakeArray(context, n_layouts, args, exception);
g_free(args); g_free(args);
if (array == NULL)
return JSValueMakeNull (context); if (array == NULL) {
else return JSValueMakeNull(context);
} else {
return array; return array;
}
} }
@ -474,12 +499,14 @@ set_layout_cb(JSContextRef context,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef value, JSValueRef value,
JSValueRef *exception) { JSValueRef *exception) {
gchar *layout;
gchar *layout;
const GList *layouts, *link; const GList *layouts, *link;
layout = arg_to_string(context, value, exception);
layout = arg_to_string (context, value, exception); if (!layout) {
if (!layout)
return false; return false;
}
layouts = lightdm_get_layouts(); layouts = lightdm_get_layouts();
@ -494,6 +521,7 @@ set_layout_cb(JSContextRef context,
} }
g_free(layout); g_free(layout);
return true; return true;
} }
@ -503,6 +531,7 @@ get_sessions_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef *exception) { JSValueRef *exception) {
JSObjectRef array; JSObjectRef array;
const GList *sessions, *link; const GList *sessions, *link;
guint i, n_sessions = 0; guint i, n_sessions = 0;
@ -521,10 +550,12 @@ get_sessions_cb(JSContextRef context,
array = JSObjectMakeArray(context, n_sessions, args, exception); array = JSObjectMakeArray(context, n_sessions, args, exception);
g_free(args); g_free(args);
if (array == NULL)
return JSValueMakeNull (context); if (array == NULL) {
else return JSValueMakeNull(context);
} else {
return array; return array;
}
} }
@ -557,66 +588,76 @@ get_autologin_timeout_cb(JSContextRef context,
static JSValueRef static JSValueRef
cancel_autologin_cb(JSContextRef context, cancel_autologin_cb(JSContextRef context,
JSObjectRef function, JSObjectRef function,
JSObjectRef thisObject, JSObjectRef thisObject,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
lightdm_greeter_cancel_autologin(GREETER); lightdm_greeter_cancel_autologin(GREETER);
return JSValueMakeNull(context); return JSValueMakeNull(context);
} }
static JSValueRef static JSValueRef
authenticate_cb(JSContextRef context, authenticate_cb(JSContextRef context,
JSObjectRef function, JSObjectRef function,
JSObjectRef thisObject, JSObjectRef thisObject,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
gchar *name = NULL;
gchar *name = NULL;
if (argumentCount > 0) if (argumentCount > 0) {
name = arg_to_string (context, arguments[0], exception); name = arg_to_string(context, arguments[0], exception);
}
lightdm_greeter_authenticate (GREETER, name); lightdm_greeter_authenticate(GREETER, name);
g_free(name);
g_free (name); return JSValueMakeNull(context);
return JSValueMakeNull (context);
} }
static JSValueRef static JSValueRef
authenticate_as_guest_cb (JSContextRef context, authenticate_as_guest_cb(JSContextRef context,
JSObjectRef function, JSObjectRef function,
JSObjectRef thisObject, JSObjectRef thisObject,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef * exception) { JSValueRef *exception) {
lightdm_greeter_authenticate_as_guest (GREETER);
return JSValueMakeNull (context); lightdm_greeter_authenticate_as_guest(GREETER);
return JSValueMakeNull(context);
} }
static JSValueRef static JSValueRef
get_hint_cb (JSContextRef context, get_hint_cb(JSContextRef context,
JSObjectRef function, JSObjectRef function,
JSObjectRef thisObject, JSObjectRef thisObject,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef * exception) { JSValueRef *exception) {
gchar *hint_name; gchar *hint_name;
JSValueRef result; JSValueRef result;
if (argumentCount != 1) if (argumentCount != 1) {
return mkexception (context, exception, "Hint argument not supplied"); return mkexception(context, exception, "Hint argument not supplied");
}
hint_name = arg_to_string(context, arguments[0], exception);
hint_name = arg_to_string (context, arguments[0], exception); if (!hint_name) {
if (!hint_name) return JSValueMakeNull(context);
return JSValueMakeNull (context); }
result = string_or_null (context, lightdm_greeter_get_hint (GREETER, hint_name)); result = string_or_null(context, lightdm_greeter_get_hint(GREETER, hint_name));
g_free (hint_name); g_free(hint_name);
return result; return result;
} }
@ -624,24 +665,28 @@ get_hint_cb (JSContextRef context,
static JSValueRef static JSValueRef
respond_cb(JSContextRef context, respond_cb(JSContextRef context,
JSObjectRef function, JSObjectRef function,
JSObjectRef thisObject, JSObjectRef thisObject,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
gchar *response; gchar *response;
if (argumentCount != 1) if (argumentCount != 1) {
return mkexception (context, exception, "Response not supplied"); return mkexception(context, exception, "Response not supplied");
}
response = arg_to_string(context, arguments[0], exception);
response = arg_to_string (context, arguments[0], exception); if (!response) {
if (!response) return JSValueMakeNull(context);
return JSValueMakeNull (context); }
lightdm_greeter_respond (GREETER, response); lightdm_greeter_respond(GREETER, response);
g_free(response);
g_free (response); return JSValueMakeNull(context);
return JSValueMakeNull (context);
} }
@ -652,7 +697,9 @@ cancel_authentication_cb(JSContextRef context,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
lightdm_greeter_cancel_authentication(GREETER); lightdm_greeter_cancel_authentication(GREETER);
return JSValueMakeNull(context); return JSValueMakeNull(context);
} }
@ -667,56 +714,56 @@ get_authentication_user_cb(JSContextRef context,
static JSValueRef static JSValueRef
get_has_guest_account_cb (JSContextRef context, get_has_guest_account_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef * exception) { JSValueRef *exception) {
return JSValueMakeBoolean (context, lightdm_greeter_get_has_guest_account_hint (GREETER)); return JSValueMakeBoolean(context, lightdm_greeter_get_has_guest_account_hint(GREETER));
} }
static JSValueRef static JSValueRef
get_hide_users_cb (JSContextRef context, get_hide_users_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef * exception) { JSValueRef *exception) {
return JSValueMakeBoolean (context, lightdm_greeter_get_hide_users_hint (GREETER)); return JSValueMakeBoolean(context, lightdm_greeter_get_hide_users_hint(GREETER));
} }
static JSValueRef static JSValueRef
get_select_user_cb (JSContextRef context, get_select_user_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef * exception) { JSValueRef *exception) {
return string_or_null (context, lightdm_greeter_get_select_user_hint (GREETER)); return string_or_null(context, lightdm_greeter_get_select_user_hint(GREETER));
} }
static JSValueRef static JSValueRef
get_select_guest_cb (JSContextRef context, get_select_guest_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef * exception) { JSValueRef *exception) {
return JSValueMakeBoolean (context, lightdm_greeter_get_select_guest_hint (GREETER)); return JSValueMakeBoolean(context, lightdm_greeter_get_select_guest_hint(GREETER));
} }
static JSValueRef static JSValueRef
get_autologin_user_cb (JSContextRef context, get_autologin_user_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef * exception) { JSValueRef *exception) {
return string_or_null (context, lightdm_greeter_get_autologin_user_hint (GREETER)); return string_or_null(context, lightdm_greeter_get_autologin_user_hint(GREETER));
} }
static JSValueRef static JSValueRef
get_autologin_guest_cb (JSContextRef context, get_autologin_guest_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef * exception) { JSValueRef *exception) {
return JSValueMakeBoolean (context, lightdm_greeter_get_autologin_guest_hint (GREETER)); return JSValueMakeBoolean(context, lightdm_greeter_get_autologin_guest_hint(GREETER));
} }
@ -731,9 +778,9 @@ get_is_authenticated_cb(JSContextRef context,
static JSValueRef static JSValueRef
get_in_authentication_cb(JSContextRef context, get_in_authentication_cb(JSContextRef context,
JSObjectRef thisObject, JSObjectRef thisObject,
JSStringRef propertyName, JSStringRef propertyName,
JSValueRef *exception) { JSValueRef *exception) {
return JSValueMakeBoolean(context, lightdm_greeter_get_in_authentication(GREETER)); return JSValueMakeBoolean(context, lightdm_greeter_get_in_authentication(GREETER));
} }
@ -755,6 +802,7 @@ suspend_cb(JSContextRef context,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
lightdm_suspend(NULL); lightdm_suspend(NULL);
return JSValueMakeNull(context); return JSValueMakeNull(context);
@ -778,6 +826,7 @@ hibernate_cb(JSContextRef context,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
lightdm_hibernate(NULL); lightdm_hibernate(NULL);
return JSValueMakeNull(context); return JSValueMakeNull(context);
@ -801,6 +850,7 @@ restart_cb(JSContextRef context,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
lightdm_restart(NULL); lightdm_restart(NULL);
return JSValueMakeNull(context); return JSValueMakeNull(context);
@ -824,6 +874,7 @@ shutdown_cb(JSContextRef context,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
lightdm_shutdown(NULL); lightdm_shutdown(NULL);
return JSValueMakeNull(context); return JSValueMakeNull(context);
@ -832,11 +883,12 @@ shutdown_cb(JSContextRef context,
static JSValueRef static JSValueRef
start_session_sync_cb(JSContextRef context, start_session_sync_cb(JSContextRef context,
JSObjectRef function, JSObjectRef function,
JSObjectRef thisObject, JSObjectRef thisObject,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
gchar *session = NULL; gchar *session = NULL;
gboolean result; gboolean result;
GError *err = NULL; GError *err = NULL;
@ -845,26 +897,26 @@ start_session_sync_cb(JSContextRef context,
* is never actually used. At some point, deprecate the old usage. For now, * is never actually used. At some point, deprecate the old usage. For now,
* simply work around it. */ * simply work around it. */
if (argumentCount == 1) if (argumentCount == 1) {
session = arg_to_string (context, arguments[0], exception); session = arg_to_string(context, arguments[0], exception);
else if (argumentCount == 2) } else if (argumentCount == 2) {
session = arg_to_string (context, arguments[1], exception); session = arg_to_string(context, arguments[1], exception);
else if (argumentCount == 0) } else if (argumentCount == 0) {
session = NULL; session = NULL;
else { } else {
_mkexception (context, exception, "Incorrect parameters"); _mkexception(context, exception, "Incorrect parameters");
return JSValueMakeBoolean (context, FALSE); return JSValueMakeBoolean(context, FALSE);
} }
result = lightdm_greeter_start_session_sync (GREETER, session, &err); result = lightdm_greeter_start_session_sync(GREETER, session, &err);
g_free(session);
g_free (session);
if (err != NULL) { if (err != NULL) {
_mkexception (context, exception, err->message); _mkexception(context, exception, err->message);
g_error_free (err); g_error_free(err);
} }
return JSValueMakeBoolean (context, result); return JSValueMakeBoolean(context, result);
} }
@ -875,19 +927,24 @@ set_language_cb(JSContextRef context,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
gchar *language; gchar *language;
if (argumentCount != 1) if (argumentCount != 1) {
return mkexception (context, exception, "Language not supplied"); return mkexception(context, exception, "Language not supplied");
}
language = arg_to_string(context, arguments[0], exception);
if (!language) {
return JSValueMakeNull(context);
}
language = arg_to_string (context, arguments[0], exception); lightdm_greeter_set_language(GREETER, language);
if (!language)
return JSValueMakeNull (context);
lightdm_greeter_set_language (GREETER, language); g_free(language);
g_free (language); return JSValueMakeNull(context);
return JSValueMakeNull (context);
} }
@ -898,17 +955,22 @@ gettext_cb(JSContextRef context,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
gchar *string; gchar *string;
JSValueRef result; JSValueRef result;
if (argumentCount != 1) if (argumentCount != 1) {
return mkexception (context, exception, "Argument not supplied"); return mkexception(context, exception, "Argument not supplied");
}
string = arg_to_string(context, arguments[0], exception);
if (!string) {
return JSValueMakeNull(context);
}
string = arg_to_string (context, arguments[0], exception); result = string_or_null(context, gettext(string));
if (!string) g_free(string);
return JSValueMakeNull (context);
result = string_or_null (context, gettext (string));
g_free (string);
return result; return result;
} }
@ -921,6 +983,7 @@ ngettext_cb(JSContextRef context,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
gchar *string, *plural_string; gchar *string, *plural_string;
unsigned int n; unsigned int n;
JSValueRef result; JSValueRef result;
@ -929,17 +992,23 @@ ngettext_cb(JSContextRef context,
return mkexception(context, exception, "Needs 3 arguments"); return mkexception(context, exception, "Needs 3 arguments");
} }
string = arg_to_string (context, arguments[0], exception); string = arg_to_string(context, arguments[0], exception);
if (!string)
return JSValueMakeNull (context); if (!string) {
plural_string = arg_to_string (context, arguments[1], exception); return JSValueMakeNull(context);
if (!plural_string) }
return JSValueMakeNull (context);
n = JSValueToNumber (context, arguments[2], exception);
result = string_or_null (context, ngettext (string, plural_string, n)); plural_string = arg_to_string(context, arguments[1], exception);
g_free (string);
g_free (plural_string); if (!plural_string) {
return JSValueMakeNull(context);
}
n = JSValueToNumber(context, arguments[2], exception);
result = string_or_null(context, ngettext(string, plural_string, n));
g_free(string);
g_free(plural_string);
return result; return result;
} }
@ -1117,6 +1186,7 @@ window_object_cleared_callback(WebKitScriptWorld *world,
lightdm_session_class = JSClassCreate(&lightdm_session_definition); lightdm_session_class = JSClassCreate(&lightdm_session_definition);
gettext_object = JSObjectMake(jsContext, gettext_class, NULL); gettext_object = JSObjectMake(jsContext, gettext_class, NULL);
JSObjectSetProperty(jsContext, JSObjectSetProperty(jsContext,
globalObject, globalObject,
JSStringCreateWithUTF8CString("gettext"), JSStringCreateWithUTF8CString("gettext"),
@ -1125,6 +1195,7 @@ window_object_cleared_callback(WebKitScriptWorld *world,
NULL); NULL);
lightdm_greeter_object = JSObjectMake(jsContext, lightdm_greeter_class, greeter); lightdm_greeter_object = JSObjectMake(jsContext, lightdm_greeter_class, greeter);
JSObjectSetProperty(jsContext, JSObjectSetProperty(jsContext,
globalObject, globalObject,
JSStringCreateWithUTF8CString("lightdm"), JSStringCreateWithUTF8CString("lightdm"),
@ -1228,8 +1299,7 @@ show_message_cb(LightDMGreeter *greeter,
static void static void
authentication_complete_cb(LightDMGreeter *greeter, authentication_complete_cb(LightDMGreeter *greeter, WebKitWebExtension *extension) {
WebKitWebExtension *extension) {
WebKitWebPage *web_page; WebKitWebPage *web_page;
WebKitFrame *web_frame; WebKitFrame *web_frame;
@ -1240,9 +1310,7 @@ authentication_complete_cb(LightDMGreeter *greeter,
if (web_page != NULL) { if (web_page != NULL) {
web_frame = webkit_web_page_get_main_frame(web_page); web_frame = webkit_web_page_get_main_frame(web_page);
jsContext = webkit_frame_get_javascript_global_context(web_frame); jsContext = webkit_frame_get_javascript_global_context(web_frame);
command = JSStringCreateWithUTF8CString("authentication_complete()"); command = JSStringCreateWithUTF8CString("authentication_complete()");
JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL);
@ -1251,8 +1319,7 @@ authentication_complete_cb(LightDMGreeter *greeter,
static void static void
autologin_timer_expired_cb(LightDMGreeter *greeter, autologin_timer_expired_cb(LightDMGreeter *greeter, WebKitWebExtension *extension) {
WebKitWebExtension *extension) {
WebKitWebPage *web_page; WebKitWebPage *web_page;
WebKitFrame *web_frame; WebKitFrame *web_frame;
@ -1263,9 +1330,7 @@ autologin_timer_expired_cb(LightDMGreeter *greeter,
if (web_page != NULL) { if (web_page != NULL) {
web_frame = webkit_web_page_get_main_frame(web_page); web_frame = webkit_web_page_get_main_frame(web_page);
jsContext = webkit_frame_get_javascript_global_context(web_frame); jsContext = webkit_frame_get_javascript_global_context(web_frame);
command = JSStringCreateWithUTF8CString("autologin_timer_expired()"); command = JSStringCreateWithUTF8CString("autologin_timer_expired()");
JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL);

52
src/lightdm-webkit2-greeter.c

@ -1,7 +1,7 @@
/* /*
* lightdm-webkit2-greeter.c * 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: * Based on code from lightdm-webkit-greeter:
* Copyright © 2010-2015 Robert Ancell <robert.ancell@canonical.com> * Copyright © 2010-2015 Robert Ancell <robert.ancell@canonical.com>
@ -45,23 +45,23 @@
#include "src/lightdm-webkit2-greeter-css-application.h" #include "src/lightdm-webkit2-greeter-css-application.h"
static GtkWidget *web_view; static GtkWidget *web_view;
static GtkWidget *window; static GtkWidget *window;
static WebKitSettings *webkit_settings; static WebKitSettings *webkit_settings;
static GdkDisplay *default_display; static GdkDisplay *default_display;
/* Screensaver values */ /* Screensaver values */
static int timeout, interval, prefer_blanking, allow_exposures; static int timeout, interval, prefer_blanking, allow_exposures;
static gint config_timeout; static gint config_timeout;
static GdkFilterReturn static GdkFilterReturn
wm_window_filter(GdkXEvent *gxevent, GdkEvent *event, gpointer data) { wm_window_filter(GdkXEvent *gxevent, GdkEvent *event, gpointer data) {
XEvent *xevent = (XEvent *) gxevent; XEvent *xevent = (XEvent *) gxevent;
if (xevent->type == MapNotify) { if (xevent->type == MapNotify) {
GdkDisplay *display = gdk_x11_lookup_xdisplay(xevent->xmap.display); GdkDisplay *display = gdk_x11_lookup_xdisplay(xevent->xmap.display);
GdkWindow *win = gdk_x11_window_foreign_new_for_display(display, xevent->xmap.window); GdkWindow *win = gdk_x11_window_foreign_new_for_display(display, xevent->xmap.window);
GdkWindowTypeHint win_type = gdk_window_get_type_hint(win); GdkWindowTypeHint win_type = gdk_window_get_type_hint(win);
if (win_type != GDK_WINDOW_TYPE_HINT_COMBO if (win_type != GDK_WINDOW_TYPE_HINT_COMBO
@ -73,7 +73,7 @@ wm_window_filter(GdkXEvent *gxevent, GdkEvent *event, gpointer data) {
} else if (xevent->type == UnmapNotify) { } else if (xevent->type == UnmapNotify) {
Window xwin; Window xwin;
int revert_to = RevertToNone; int revert_to = RevertToNone;
XGetInputFocus(xevent->xunmap.display, &xwin, &revert_to); XGetInputFocus(xevent->xunmap.display, &xwin, &revert_to);
if (revert_to == RevertToNone) { if (revert_to == RevertToNone) {
@ -117,14 +117,16 @@ context_menu_cb(WebKitWebView *view,
GdkEvent *event, GdkEvent *event,
WebKitHitTestResult *hit_test_result, WebKitHitTestResult *hit_test_result,
gpointer user_data) { gpointer user_data) {
return TRUE; return TRUE;
} }
static void static void
greeter_bridge_lock_hint_cb(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); Display *display = gdk_x11_display_get_xdisplay(default_display);
XGetScreenSaver(display, &timeout, &interval, &prefer_blanking, &allow_exposures); XGetScreenSaver(display, &timeout, &interval, &prefer_blanking, &allow_exposures);
XForceScreenSaver(display, ScreenSaverActive); XForceScreenSaver(display, ScreenSaverActive);
XSetScreenSaver(display, XSetScreenSaver(display,
@ -141,7 +143,8 @@ message_received_cb(WebKitUserContentManager *manager,
gpointer user_data) { gpointer user_data) {
/* TODO: /* 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(); greeter_bridge_lock_hint_cb();
@ -151,13 +154,14 @@ message_received_cb(WebKitUserContentManager *manager,
static gboolean static gboolean
fade_timer_cb(gpointer data) { fade_timer_cb(gpointer data) {
gdouble opacity; gdouble opacity;
opacity = gtk_widget_get_opacity(web_view); opacity = gtk_widget_get_opacity(web_view);
opacity -= 0.1; opacity -= 0.1;
if (opacity <= 0) { if (opacity <= 0) {
gtk_main_quit(); gtk_main_quit();
return FALSE; return FALSE;
} }
gtk_widget_set_opacity(web_view, opacity); gtk_widget_set_opacity(web_view, opacity);
return TRUE; return TRUE;
@ -174,15 +178,15 @@ quit_cb(void) {
int int
main(int argc, char **argv) { main(int argc, char **argv) {
GdkScreen *screen; GdkScreen *screen;
GdkWindow *root_window; GdkWindow *root_window;
GdkRectangle geometry; GdkRectangle geometry;
GKeyFile *keyfile; GKeyFile *keyfile;
gchar *theme; gchar *theme;
GdkRGBA bg_color; GdkRGBA bg_color;
WebKitUserContentManager *manager; WebKitUserContentManager *manager;
WebKitWebContext *context; WebKitWebContext *context;
GtkCssProvider *css_provider; GtkCssProvider *css_provider;
g_unix_signal_add(SIGTERM, (GSourceFunc) quit_cb, /* is_callback */ GINT_TO_POINTER(TRUE)); g_unix_signal_add(SIGTERM, (GSourceFunc) quit_cb, /* is_callback */ GINT_TO_POINTER(TRUE));
@ -191,13 +195,13 @@ main(int argc, char **argv) {
// Apply greeter settings from conf file // Apply greeter settings from conf file
keyfile = g_key_file_new(); keyfile = g_key_file_new();
g_key_file_load_from_file(keyfile, CONFIG_DIR "/lightdm-webkit2-greeter.conf", G_KEY_FILE_NONE, NULL); g_key_file_load_from_file(keyfile, CONFIG_DIR "/lightdm-webkit2-greeter.conf", G_KEY_FILE_NONE, NULL);
theme = g_key_file_get_string(keyfile, "greeter", "webkit-theme", NULL); theme = g_key_file_get_string(keyfile, "greeter", "webkit-theme", NULL);
config_timeout = g_key_file_get_integer(keyfile, "greeter", "screensaver-timeout", NULL); config_timeout = g_key_file_get_integer(keyfile, "greeter", "screensaver-timeout", NULL);
// Setup the main window // Setup the main window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
screen = gtk_window_get_screen(GTK_WINDOW(window)); screen = gtk_window_get_screen(GTK_WINDOW(window));
root_window = gdk_get_default_root_window(); root_window = gdk_get_default_root_window();
default_display = gdk_display_get_default(); default_display = gdk_display_get_default();
gtk_window_set_decorated(GTK_WINDOW(window), FALSE); gtk_window_set_decorated(GTK_WINDOW(window), FALSE);

Loading…
Cancel
Save