void up_single_click_handler(ClickRecognizerRef recognizer, void *context) { if (selected_number > 0 && selected_number <= 9) { selected_number--; update_bar(); } }
void status_bar() { unsigned int i, y; XSetWindowAttributes setattr; setattr.override_redirect = True; unsigned long vmask = CWOverrideRedirect; y = (topbar == 0) ? 0+ug_bar : desktops[barmon].h+bdw-ug_bar; sb_width = ug_bar; for(i=0;i<DESKTOPS;++i) { sb_bar[i].sb_win = XCreateSimpleWindow(dis, root, desktops[barmon].x+sb_width, y, sb_bar[i].width-2,sb_height,2,theme[3].barcolor,theme[0].barcolor); XSelectInput(dis, sb_bar[i].sb_win, ButtonPressMask|EnterWindowMask|LeaveWindowMask); XChangeWindowAttributes(dis, sb_bar[i].sb_win, vmask, &setattr); XMapWindow(dis, sb_bar[i].sb_win); sb_width += sb_bar[i].width; } sb_area = XCreateSimpleWindow(dis, root, desktops[barmon].x+sb_desks+ug_bar, y, desktops[barmon].w-lessbar-(sb_desks+2)-2*ug_bar,sb_height,2,theme[3].barcolor,theme[1].barcolor); XSelectInput(dis, sb_area, ButtonPressMask|ExposureMask|EnterWindowMask|LeaveWindowMask); XChangeWindowAttributes(dis, sb_area, vmask, &setattr); XMapWindow(dis, sb_area); XWindowAttributes attr; XGetWindowAttributes(dis, sb_area, &attr); total_w = attr.width; area_sb = XCreatePixmap(dis, root, total_w, sb_height, DefaultDepth(dis, screen)); XFillRectangle(dis, area_sb, theme[0].gc, 0, 0, total_w, sb_height+4); status_text(""); update_bar(); }
void toggle_bar() { if(desktops[current_desktop].screen != barmon) return; if(STATUS_BAR == 0) { if(has_bar == 0) { show_bar = 1; unmapbar(); desktops[current_desktop].h += sb_height+4+ug_bar; } else { show_bar = 0; mapbar(); desktops[current_desktop].h -= sb_height+4+ug_bar; update_bar(); } sh = desktops[current_desktop].h; tile(); } }
void down_single_click_handler(ClickRecognizerRef recognizer, void *context) { if (selected_number >= 0 && selected_number < 9) { selected_number++; update_bar(); } }
void window_load(Window *window) { persist_read_string(1, saved_passcode, 50); Layer *window_layer = window_get_root_layer(window); number_0 = number_layer_init(GRect(124, 0, 20, 15), "0"); layer_add_child(window_layer, text_layer_get_layer(number_0)); number_1 = number_layer_init(GRect(124, 15, 20, 15), "1"); layer_add_child(window_layer, text_layer_get_layer(number_1)); number_2 = number_layer_init(GRect(124, 30, 20, 15), "2"); layer_add_child(window_layer, text_layer_get_layer(number_2)); number_3 = number_layer_init(GRect(124, 45, 20, 15), "3"); layer_add_child(window_layer, text_layer_get_layer(number_3)); number_4 = number_layer_init(GRect(124, 60, 20, 15), "4"); layer_add_child(window_layer, text_layer_get_layer(number_4)); number_5 = number_layer_init(GRect(124, 75, 20, 15), "5"); layer_add_child(window_layer, text_layer_get_layer(number_5)); number_6 = number_layer_init(GRect(124, 90, 20, 15), "6"); layer_add_child(window_layer, text_layer_get_layer(number_6)); number_7 = number_layer_init(GRect(124, 105, 20, 15), "7"); layer_add_child(window_layer, text_layer_get_layer(number_7)); number_8 = number_layer_init(GRect(124, 120, 20, 15), "8"); layer_add_child(window_layer, text_layer_get_layer(number_8)); number_9 = number_layer_init(GRect(124, 135, 20, 17), "9"); layer_add_child(window_layer, text_layer_get_layer(number_9)); status_text_layer = text_layer_create(GRect(0, 90, 124, 40)); text_layer_set_text_color(status_text_layer, GColorBlack); text_layer_set_font(status_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_text_alignment(status_text_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(status_text_layer)); selected_number = 0; cursor_position = 0; circle_layer = layer_create(GRect(0, 20, 144, 100)); layer_set_update_proc(circle_layer, circle_proc); layer_add_child(window_layer, circle_layer); update_bar(); window_set_click_config_provider(window, (ClickConfigProvider) config_provider); line = gbitmap_create_with_resource(RESOURCE_ID_LINE); line_layer = bitmap_layer_create(GRect(122, 0, 2, 168)); bitmap_layer_set_alignment(line_layer, GAlignCenter); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(line_layer)); bitmap_layer_set_bitmap(line_layer, line); theme = inverter_layer_create(GRect(0, 0, 144, 168)); layer_add_child(window_layer, inverter_layer_get_layer(theme)); layer_set_hidden(inverter_layer_get_layer(theme), theme_public); }
int copy_async_gbl(char *path1, char *path2, u64 size, char *progress_string1, char *progress_string2) { int ret = 0; FILE *fp = NULL; FILE *fp2 = NULL; float parts = 0; float cpart; char buffer[16384]; use_async_fd = 128; my_f_async.flags = 0; single_bar(progress_string1); parts = (size == 0) ? 0.0f : 100.0f / ((double) size / (double) sizeof(buffer)); cpart = 0; fp = fopen(path1, "rb"); if(!fp) {ret = -1; goto err;} fp2 = fopen(path2, "wb"); if(!fp2) {ret = -2; goto err;} int acum = 0; while (size != 0ULL) { int recv = (size > 16384) ? 16384 : size; recv = fread(buffer, 1, recv, fp); if (recv <= 0) break; if (recv > 0) { loop_write: if(use_async_fd == 128) { use_async_fd = 1; my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp2; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { if(!(my_f_async.flags & ASYNC_ENABLE)) { if(my_f_async.flags & ASYNC_ERROR) { fclose(fp2); fp2 = NULL; ret = -6; goto err; } my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp2; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { goto loop_write; } } /////////////////// size -= recv; acum+= recv; } if(progress_action == 2) {ret = -0x555; goto err;} pad_last_time = 0; if(1) { if(acum >= sizeof(buffer)) { acum-= sizeof(buffer); cpart += parts; if(cpart >= 1.0f) { update_bar((u32) cpart); cpart-= (float) ((u32) cpart); } } } } ret = 0; err: if(my_f_async.flags & ASYNC_ENABLE){ wait_event_thread(); if(my_f_async.flags & ASYNC_ERROR) { if(fp2) fclose(fp2); fp2 = NULL; ret = -6; } my_f_async.flags = 0; } event_thread_send(0x555ULL, (u64) 0, 0); msgDialogAbort(); if(fp) { fclose(fp); } if(fp2) { fclose(fp2); if(ret < 0) unlink_secure(path2); } return ret; }
static int download_file(char *url, char *file, int mode, u64 *size) { int flags = 0; int ret = 0; void *http_p = NULL; void *uri_p = NULL; httpUri uri; s32 transID = 0; s32 clientID; int pool_size = 0; int recv = -1; u64 length = 0; int code = 0; FILE *fp = NULL; float parts = 0; float cpart; char buffer[16384]; use_async_fd = 128; my_f_async.flags = 0; if(mode == 2) { if(size) sprintf(temp_buffer + 4096, "File Size: %u MB\n%s", (u32) (*size/0x100000ULL), strrchr(file, '/') + 1); else sprintf(temp_buffer + 4096, "File: %s", strrchr(file, '/') + 1); single_bar(temp_buffer + 4096); } http_p = malloc(0x10000); if(!http_p) {ret= -1; goto err;} ret = httpInit(http_p, 0x10000); if(ret < 0) goto err; flags|= 1; ret = httpCreateClient(&clientID); if(ret < 0) goto err; flags|= 2; httpClientSetConnTimeout(clientID, 10000000); ret = httpUtilParseUri(NULL, url, NULL, 0, &pool_size); if (ret < 0) goto err; uri_p = malloc(pool_size); if (!uri_p) goto err; ret = httpUtilParseUri(&uri, url, uri_p, pool_size, NULL); if (ret < 0) goto err; ret = httpCreateTransaction(&transID, clientID, HTTP_METHOD_GET, &uri); if (ret < 0) goto err; free(uri_p); uri_p = NULL; ret = httpSendRequest(transID, NULL, 0, NULL); if (ret < 0) goto err; ret = httpResponseGetStatusCode(transID, &code); if (ret < 0) goto err; if (code == 404 || code == 403) {ret=-4; goto err;} ret = httpResponseGetContentLength(transID, &length); if (ret < 0) { if (ret == HTTP_STATUS_CODE_No_Content) { length = 0ULL; ret = 0; } else goto err; } if(size) *size = length; if(mode == 1) goto err; // get only the size if(mode == 2) { parts = (length == 0) ? 0.0f : 100.0f / ((double) length / (double) sizeof(buffer)); cpart = 0; } fp = fopen(file, "wb"); if(!fp) goto err; int acum = 0; while (recv != 0 && length != 0ULL) { memset(buffer, 0x0, sizeof(buffer)); if (httpRecvResponse(transID, buffer, sizeof(buffer) - 1, &recv) < 0) {fclose(fp); ret = -5; goto err;} if (recv == 0) break; if (recv > 0) { //if(fwrite(buffer, 1, recv, fp) != recv) {fclose(fp); fp = NULL; ret = -6; goto err;} /////////////////// loop_write: if(use_async_fd == 128) { use_async_fd = 1; my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { if(!(my_f_async.flags & ASYNC_ENABLE)) { if(my_f_async.flags & ASYNC_ERROR) { fclose(fp); fp = NULL; ret = -6; goto err; } my_f_async.flags = 0; my_f_async.size = recv; my_f_async.fp = fp; my_f_async.mem = malloc(recv); if(my_f_async.mem) memcpy(my_f_async.mem, (void *) buffer, recv); my_f_async.ret = -1; my_f_async.flags = ASYNC_ENABLE; event_thread_send(0x555ULL, (u64) my_func_async, (u64) &my_f_async); } else { goto loop_write; } } /////////////////// length -= recv; acum+= recv; } if(mode == 2 && progress_action == 2) {ret = -0x555; goto err;} pad_last_time = 0; if(mode == 2) { if(acum >= sizeof(buffer)) { acum-= sizeof(buffer); cpart += parts; if(cpart >= 1.0f) { update_bar((u32) cpart); cpart-= (float) ((u32) cpart); } } } } ret = 0; err: if(my_f_async.flags & ASYNC_ENABLE){ wait_event_thread(); if(my_f_async.flags & ASYNC_ERROR) { if(fp) fclose(fp); fp = NULL; ret = -6; } my_f_async.flags = 0; } event_thread_send(0x555ULL, (u64) 0, 0); if(mode == 2) { msgDialogAbort(); } if(fp) { fclose(fp); if(ret < 0) unlink_secure(file); } if(transID) httpDestroyTransaction(transID); if(flags & 2) httpDestroyClient(clientID); if(flags & 1) httpEnd(); if(http_p) free(http_p); if(uri_p) free(uri_p); return ret; }
int main(int argc, char const *argv[]) { shmem *mem; const char *geometry; int lemon_in, lemon_out; int tries=0; struct pollfd fds[1]; fds[0].events = POLLIN; geometry = (argc < 2) ? DEFAULT_GEOM : argv[1]; if (validate_geometry(geometry) < 0){ fprintf(stderr, "please provide a valid window geometry. E.g. 1920x22+0+0 (widthxheight+X+Y)\n"); return -1; } if ((mem = setup_memory(0)) == MEM_FAILED){ printf("Spawning data daemon\n"); if (spawn_daemon() < 0){ fprintf(stderr, "failed to start daemon\n"); exit(-1); } while ((mem = setup_memory(0)) == MEM_FAILED){ if (tries++ > 10){ fprintf(stderr, "failed to connect to daemon\n"); exit(-1); } sleep(1); } printf("connected to new data source\n"); } else { printf("Connected to running data source.\n"); } spawn_bar(&lemon_in, &lemon_out, geometry); fds[0].fd = lemon_out; notify_server(mem->server); catch_signals(); //@todo allow an escape for when server dies while (1) { DEBUG_(printf("waiting for wakeup signal\n")); //block. wait here for lemonbar click output, or update signal from server //we could block with read() or something, but let's plan for multiple //sources for the future. if (poll(fds, 1, -1) < 0){ if (errno != EINTR){ perror("poll"); break; } } if (fds[0].revents & POLLIN) { fds[0].revents = 0; //clear for next round //something was clicked process_click(fds[0].fd); } else { //must have gotten pinged by server //@todo verify SIGUSR1 vs other signals (which generally just exit anyway) update_bar(mem,lemon_in); } } return -1; }