viking

webkit based web browser for Enlightenment
Log | Files | Refs | LICENSE

commit 914066ca5d1bfb3d8ef32f502bf46354df5f7dbb
parent ead982fcbf4a9f0f62c94dc50cd8b61e3d7ac73b
Author: Kyle Milz <kmilz@ucalgary.ca>
Date:   Sat,  6 Oct 2012 20:13:35 -0600

spawn new windows when new program instances are run

do this so there is never more than 1 main browser process running.

Diffstat:
Msrc/commands.c | 18++++++------------
Msrc/main.c | 46+++++++++++++++++++---------------------------
Msrc/utilities.c | 20++++++++++----------
Msrc/utilities.h | 2+-
Msrc/viking.h | 8++++++--
5 files changed, 42 insertions(+), 52 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -553,12 +553,11 @@ open_arg(const Arg *arg, void *data) ewk_view_uri_set(ad->cur_buf->view, new); free(new); } else { - a.i = CreateAndShow; + a.i = SwitchToBuffer; buffer_add(&a, ad); a.i = TargetCurrent; - a.s = strdup(arg->s); // not sure if strdup necessary - open_arg(&a, data); - free(a.s); + a.s = arg->s; + open_arg(&a, ad); } return TRUE; } @@ -1478,17 +1477,12 @@ toggle_cookies(const Arg *arg, void *data) Eina_Bool window(const Arg *arg, void *data) { - Arg a; Window_Data *wd = data; - if (arg->i & CreateWindow) { - a.i = DefaultBuf; - a.s = (char*)(arg->s ? arg->s : config_home_page_get(wd->app->config)); - window_add(&a, wd->app); - } - else if (arg->i & DeleteWindow) { + if (arg->i & CreateWindow) + window_add(wd->app); + else if (arg->i & DeleteWindow) evas_object_del(wd->win); - } return EINA_TRUE; } diff --git a/src/main.c b/src/main.c @@ -167,13 +167,6 @@ _client_add(void *data, int type, Ecore_Con_Event_Server_Add *ev) { char *url = data; - printf("_client_add() %s\n", url); - - printf("Server with ip %s, name %s, port %d, connected = %d!\n", - ecore_con_server_ip_get(ev->server), - ecore_con_server_name_get(ev->server), - ecore_con_server_port_get(ev->server), - ecore_con_server_connected_get(ev->server)); ecore_con_server_send(ev->server, url, strlen(url)); ecore_con_server_flush(ev->server); @@ -191,8 +184,6 @@ _client_del(void *data, int type, Ecore_Con_Event_Server_Del *ev) return ECORE_CALLBACK_RENEW; } - printf("Lost server with ip %s!\n", ecore_con_server_ip_get(ev->server)); - ecore_con_server_del(ev->server); ecore_main_loop_quit(); @@ -202,17 +193,20 @@ _client_del(void *data, int type, Ecore_Con_Event_Server_Del *ev) static Eina_Bool _server_data(void *data, int type, Ecore_Con_Event_Client_Data *ev) { - char fmt[128]; + Arg arg; + char *uri = ev->data; + App_Data *ad = data; - snprintf(fmt, sizeof(fmt), - "Received %i bytes from client %s port %d:\n" - ">>>>>\n" - "%%.%is\n" - ">>>>>\n", - ev->size, ecore_con_client_ip_get(ev->client), - ecore_con_client_port_get(ev->client), ev->size); - - printf(fmt, ev->data); + arg.i = SwitchToBuffer; + if (!strncmp(uri, "NULL", 4)) + arg.i |= DefaultUrl; + else { + arg.i |= CustomUrl; + arg.s = uri; + } + /* second arg can be NULL because InNewWindow flag set */ + Window_Data *wd = window_add(ad); + buffer_add(&arg, wd); return ECORE_CALLBACK_RENEW; } @@ -223,10 +217,7 @@ _server_del(void *data, int type, Ecore_Con_Event_Client_Del *ev) if (!ev->client) return ECORE_CALLBACK_RENEW; - printf("Lost client with ip %s!\n", ecore_con_client_ip_get(ev->client)); - ecore_con_client_del(ev->client); - return ECORE_CALLBACK_RENEW; } @@ -268,7 +259,6 @@ elm_main(int argc, char *argv[]) if (!uri) uri = "NULL"; - printf("server found, sending url ..\n"); ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_client_add, uri); ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, @@ -365,9 +355,9 @@ elm_main(int argc, char *argv[]) } ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, - (Ecore_Event_Handler_Cb)_server_del, NULL); + (Ecore_Event_Handler_Cb)_server_del, ad); ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, - (Ecore_Event_Handler_Cb)_server_data, NULL); + (Ecore_Event_Handler_Cb)_server_data, ad); ecore_con_server_timeout_set(svr, 10); // ecore_con_server_client_limit_set(svr, 3, 0); @@ -377,8 +367,10 @@ elm_main(int argc, char *argv[]) } else { Arg arg; - arg.i = DefaultBuf; - window_add(&arg, ad); + arg.i = SwitchToBuffer | (uri ? CustomUrl : DefaultUrl); + arg.s = (uri ? uri : NULL); + Window_Data *wd = window_add(ad); + buffer_add(&arg, wd); } elm_run(); diff --git a/src/utilities.c b/src/utilities.c @@ -1174,6 +1174,10 @@ buffer_add(const Arg *arg, Window_Data *wd) td = calloc(1, sizeof(Buffer_Data)); if (!td) return; + /* if the InNewWindow flag is set, create the buffer in a new window */ + if (arg->i & InNewWindow) + wd = window_add(wd->app); + wd->buf_total++; td->window = wd; @@ -1213,7 +1217,7 @@ buffer_add(const Arg *arg, Window_Data *wd) else ewk_view_uri_set(td->view, config_home_page_get(wd->app->config)); - if (arg->i & CreateAndShow) + if (arg->i & SwitchToBuffer) buffer_current_set(td); } @@ -1257,8 +1261,8 @@ buffer_current_set(Buffer_Data *new_buf) } } -void -window_add(const Arg *arg, App_Data *ad) +Window_Data* +window_add(App_Data *ad) { // App_Data *ad = data; Window_Data *wd; @@ -1267,7 +1271,7 @@ window_add(const Arg *arg, App_Data *ad) unsigned int i; wd = calloc(1, sizeof(Window_Data)); - if (!wd) return; + if (!wd) return NULL; Evas_Object *win, *bg, *box, *status_bar, *url, *naviframe, *status_url; Evas_Object *status_state, *event_box, *web_inspector, *progress, *downloads; @@ -1386,14 +1390,10 @@ window_add(const Arg *arg, App_Data *ad) ad->windows = eina_list_append(ad->windows, wd); - if (arg->i & DefaultBuf) { - Arg arg; - arg.i = DefaultURL | CreateAndShow; - buffer_add(&arg, wd); - } - evas_object_resize(wd->win, 1024, 768); evas_object_show(wd->win); + + return wd; } Eina_Bool diff --git a/src/utilities.h b/src/utilities.h @@ -34,7 +34,7 @@ void userscript_hooks_start(const char*); void userscript_hooks_end(const char*); void setup_modkeys(void *data); void buffer_add(const Arg *, Window_Data *); -void window_add(const Arg *, App_Data *); +Window_Data* window_add(App_Data *); Eina_Bool echo(const Arg *arg, void *); void update_state(void *); void update_url(const char *, void *); diff --git a/src/viking.h b/src/viking.h @@ -92,8 +92,12 @@ enum { Wrapping = 1 << 3 }; enum { CreateWindow = 1 << 1, DeleteWindow = 1 << 2}; -enum { DefaultBuf = 1 << 1}; -enum { CustomUrl = 1 << 1, DefaultURL = 1 << 2, CreateAndShow = 1 << 3}; +enum { + CustomUrl = 1 << 1, + DefaultUrl = 1 << 2, + InNewWindow = 1 << 3, + SwitchToBuffer = 1 << 4 +}; /* structs here */