void moveresize_end(gboolean cancel) { ungrab_keyboard(); ungrab_pointer(); popup_hide(popup); if (!moving) { #ifdef SYNC /* turn off the alarm */ if (moveresize_alarm != None) { XSyncDestroyAlarm(obt_display, moveresize_alarm); moveresize_alarm = None; } if (sync_timer) g_source_remove(sync_timer); sync_timer = 0; #endif } /* don't use client_move() here, use the same width/height as we've been using during the move, otherwise we get different results when moving maximized windows between monitors of different sizes ! */ client_configure(moveresize_client, (cancel ? start_cx : cur_x), (cancel ? start_cy : cur_y), (cancel ? start_cw : cur_w), (cancel ? start_ch : cur_h), TRUE, TRUE, FALSE); /* restore the client's maximized state. do this after putting the window back in its original spot to minimize visible flicker */ if (cancel && (was_max_horz || was_max_vert)) { const gboolean h = moveresize_client->max_horz; const gboolean v = moveresize_client->max_vert; client_maximize(moveresize_client, TRUE, was_max_horz && was_max_vert ? 0 : (was_max_horz ? 1 : 2)); /* replace the premax values with the ones we had saved if the client doesn't have any already set */ if (was_max_horz && !h) { moveresize_client->pre_max_area.x = pre_max_area.x; moveresize_client->pre_max_area.width = pre_max_area.width; } if (was_max_vert && !v) { moveresize_client->pre_max_area.y = pre_max_area.y; moveresize_client->pre_max_area.height = pre_max_area.height; } } /* dont edge warp after its ended */ cancel_edge_warp(); moveresize_in_progress = FALSE; moveresize_client = NULL; }
void client_resize_client(Client *c, int x, int y, int w, int h) { uint32_t values[] = { x, y, w, h, c->bw }; xcb_configure_window(conn, c->win, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_BORDER_WIDTH, values); c->oldx = c->x; c->x = x; c->oldy = c->y; c->y = y; c->oldw = c->w; c->w = w; c->oldh = c->h; c->h = h; client_configure(c); xcb_flush(conn); }
/** ConfigureRequesthandle events * \param ev XConfigureRequestEvent pointer */ static void configureevent(XConfigureRequestEvent *ev) { XWindowChanges wc; Client *c; /* Check part */ if((c = client_gb_win(ev->window)) || (c = client_gb_win(ev->window))) { CHECK(!(c->flags & LMaxFlag)); CHECK(!(c->flags & MaxFlag)); CHECK(!(c->flags & FSSFlag)); } if((c = client_gb_win(ev->window))) { if(ev->value_mask & CWX) c->geo.x = ev->x + BORDH; if(ev->value_mask & CWY) c->geo.y = ev->y + TBARH; if(ev->value_mask & CWWidth) c->geo.width = ev->width; if(ev->value_mask & CWHeight) c->geo.height = ev->height; if(c->flags & FreeFlag || !(c->flags & (TileFlag | LMaxFlag))) client_moveresize(c, c->geo, False); else { client_configure(c); arrange(c->screen, True); } } else { wc.x = ev->x; wc.y = ev->y; wc.width = ev->width; wc.height = ev->height; wc.border_width = ev->border_width; wc.sibling = ev->above; wc.stack_mode = ev->detail; XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); } return; }
static void do_move(gboolean keyboard, gint keydist) { gint resist; if (keyboard) resist = keydist - 1; /* resist for one key press */ else resist = config_resist_win; resist_move_windows(moveresize_client, resist, &cur_x, &cur_y); if (!keyboard) resist = config_resist_edge; resist_move_monitors(moveresize_client, resist, &cur_x, &cur_y); client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h, TRUE, FALSE, FALSE); if (config_resize_popup_show == 2) /* == "Always" */ popup_coords(moveresize_client, "%d x %d", moveresize_client->frame->area.x, moveresize_client->frame->area.y); }
/* -------------------------------------------------------------------------- * * Speichert alle Konfigurationsdaten aus den Widgets von ui_config * * -------------------------------------------------------------------------- */ int ui_config_save(void) { int ret; ui_sound_save(); ui_config_client_save(); ui_config_card_save(); ui_config_fan_save(); ui_config_stack_save(); /* Die .ini Datei speichern */ ini_save(client_ini); /* ..und dann alle module neu konfigurieren */ ret = client_configure(); net_configure(client_ini); card_configure(client_ini); fan_configure(client_ini); // stack_configure(client_ini); return ret; }
static void do_resize(void) { gint x, y, w, h, lw, lh; /* see if it is actually going to resize USE cur_x AND cur_y HERE ! Otherwise the try_configure won't know what struts to use !! */ x = cur_x; y = cur_y; w = cur_w; h = cur_h; client_try_configure(moveresize_client, &x, &y, &w, &h, &lw, &lh, TRUE); if (!(w == moveresize_client->area.width && h == moveresize_client->area.height) && /* if waiting_for_sync == 0, then we aren't waiting. if it is > SYNC_TIMEOUTS, then we have timed out that many times already, so forget about waiting more */ (waiting_for_sync == 0 || waiting_for_sync > SYNC_TIMEOUTS)) { #ifdef SYNC if (config_resize_redraw && obt_display_extension_sync && /* don't send another sync when one is pending */ waiting_for_sync == 0 && moveresize_client->sync_request && moveresize_client->sync_counter && !moveresize_client->not_responding) { XEvent ce; XSyncValue val; /* increment the value we're waiting for */ ++moveresize_client->sync_counter_value; XSyncIntToValue(&val, moveresize_client->sync_counter_value); /* tell the client what we're waiting for */ ce.xclient.type = ClientMessage; ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS); ce.xclient.display = obt_display; ce.xclient.window = moveresize_client->window; ce.xclient.format = 32; ce.xclient.data.l[0] = OBT_PROP_ATOM(NET_WM_SYNC_REQUEST); ce.xclient.data.l[1] = event_time(); ce.xclient.data.l[2] = XSyncValueLow32(val); ce.xclient.data.l[3] = XSyncValueHigh32(val); ce.xclient.data.l[4] = 0l; XSendEvent(obt_display, moveresize_client->window, FALSE, NoEventMask, &ce); waiting_for_sync = 1; if (sync_timer) g_source_remove(sync_timer); sync_timer = g_timeout_add(2000, sync_timeout_func, NULL); } #endif /* force a ConfigureNotify, it is part of the spec for SYNC resizing and MUST follow the sync counter notification */ client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h, TRUE, FALSE, TRUE); } /* this would be better with a fixed width font ... XXX can do it better if there are 2 text boxes */ if (config_resize_popup_show == 2 || /* == "Always" */ (config_resize_popup_show == 1 && /* == "Nonpixel" */ moveresize_client->size_inc.width > 1 && moveresize_client->size_inc.height > 1)) popup_coords(moveresize_client, "%d x %d", lw, lh); }
/* -------------------------------------------------------------------------- * * Client Initialisation * * -------------------------------------------------------------------------- */ void client_init(void) { int i; SDL_RWops *rwops; const sgVersion *sgver; const SDL_version *sdlver; client_log(STATUS, "Starte "PACKAGE" v"VERSION"..."); /* GUI Library initialisieren */ sgver = sgLinkedVersion(); client_log(STATUS, "Initialisiere sgUI v%u.%u.%u", sgver->major, sgver->minor, sgver->patch); sgInit(); /* Such-Pfade adden... Alle Dateien des Tichu-Clients werden über die libsgui geöffnet Auf windows starten wir immer aus dem Programm-Verzeichnis, wir müssen also nur unsere Unterverzeichnisse kennen: */ sgAddFilePath("data"); sgAddFilePath("sounds"); sgAddFilePath("images"); /* Auf *NIXes wird immer an einen festen Pfad installiert: */ #ifdef DATADIR sgAddFilePath(DATADIR "/data"); sgAddFilePath(DATADIR "/sounds"); sgAddFilePath(DATADIR "/images"); #endif /* Vielleicht sollten wir die folgenden Pfade nur für debug-builds absuchen (#ifdef DEBUG) */ sgAddFilePath("client/data"); sgAddFilePath("client/sounds"); sgAddFilePath("client/images"); sgAddFilePath("tichu/client/data"); sgAddFilePath("tichu/client/sounds"); sgAddFilePath("tichu/client/images"); sgAddFilePath("../data"); sgAddFilePath("../sounds"); sgAddFilePath("../images"); client_path = sgGetFilePath(); /* cursors themes laden */ sgOpenCursorThemes(); /* Konfigurationsdatei öffnen */ client_ini = ini_open(CLIENT_INI, INI_READ); #ifdef DEBUG ini_dump(client_ini); #endif /* DEBUG */ if(!client_ini) client_log(ERROR, "Fehler beim Öffnen der Konfigurationsdatei %s!", CLIENT_INI); /* SDL Initialisation */ sdlver = SDL_Linked_Version(); client_log(STATUS, "Initialisiere SDL v%u.%u.%u", sdlver->major, sdlver->minor, sdlver->patch); if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE)) client_log(ERROR, "Kann SDL nicht initialisieren!"); client_subsystems = SDL_WasInit(SDL_INIT_EVERYTHING); client_getmodes(); client_configure(); #if MDEBUG_ENABLE mdebug_init(); #endif /* MDEBUG_ENABLE */ /* Netzwerk initialisieren */ net_init(); /* Module welche auf SDL basieren initialisieren */ sound_init(); // card_init("data/cards.ini", "data/cards-alpha.png"); /* net read/error funktionen */ net_register(NET_READ, client_event); net_register(NET_ERROR, client_event); #ifdef WIN32 /* Im Windows-Taskbar sieht ein 32x32 Icon am besten aus */ client_load_icon("dragon-32.png"); #else /* Unter Fluxbox und XFCE macht sich ein 16x16 Icon am Besten :P * * Oooops, unter der neuen Fluxbox mit all dem Antialias Gewixe * aber nicht, dort wäre auch ein 32x32 angebracht. * * Aber wie finden wir raus welchen WM wir runnen auf X11? * Naja, vorerst einmal scheissegal :P */ client_load_icon("dragon-16.png"); #endif /* WIN32 */ /* Window-Manager Titel setzen */ SDL_WM_SetCaption("Tichu SDL Client v"VERSION, NULL); /* Fonts laden und der GUI übergeben */ for(i = 0; i < 3; i++) { rwops = client_open_rwops(client_config.font[i], CLIENT_READ); client_font[i] = sgLoadFontRWops(rwops); } /* Einen Puffer für die Kommandozeile und Chatkonsole reservieren */ client_buffer = strdup(client_ascii); if(sound_status & SOUND_AVAIL) { sound_configure(client_ini); /* Soundeffekte laden */ ui_loadsounds(); /* Soundtracks laden */ sound_mus_scan(); if(sound_playlist.head) sound_mus_play((struct sound_mus *)sound_playlist.head); } /* Kartendaten laden */ card_configure(client_ini); card_init(); /* Fächerkonfiguration laden */ fan_configure(client_ini); }
/* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { Options *o = options; if (data->client) { Rect *area, *carea; ObClient *c; guint mon, cmon; gint x, y, lw, lh, w, h; c = data->client; mon = o->monitor; cmon = client_monitor(c); switch (mon) { case CURRENT_MONITOR: mon = cmon; break; case ALL_MONITORS: mon = SCREEN_AREA_ALL_MONITORS; break; case NEXT_MONITOR: mon = (cmon + 1 > screen_num_monitors - 1) ? 0 : (cmon + 1); break; case PREV_MONITOR: mon = (cmon == 0) ? (screen_num_monitors - 1) : (cmon - 1); break; default: g_assert_not_reached(); } area = screen_area(c->desktop, mon, NULL); carea = screen_area(c->desktop, cmon, NULL); w = o->w; if (w == G_MININT) w = c->area.width; else if (o->w_denom) w = (w * area->width) / o->w_denom; h = o->h; if (h == G_MININT) h = c->area.height; else if (o->h_denom) h = (h * area->height) / o->h_denom; /* it might not be able to resize how they requested, so find out what it will actually be resized to */ x = c->area.x; y = c->area.y; client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE); /* get the frame's size */ w += c->frame->size.left + c->frame->size.right; h += c->frame->size.top + c->frame->size.bottom; x = o->x.pos; if (o->x.denom) x = (x * area->width) / o->x.denom; if (o->x.center) x = (area->width - w) / 2; else if (x == G_MININT) x = c->frame->area.x - carea->x; else if (o->x.opposite) x = area->width - w - x; x += area->x; y = o->y.pos; if (o->y.denom) y = (y * area->height) / o->y.denom; if (o->y.center) y = (area->height - h) / 2; else if (y == G_MININT) y = c->frame->area.y - carea->y; else if (o->y.opposite) y = area->height - h - y; y += area->y; /* get the client's size back */ w -= c->frame->size.left + c->frame->size.right; h -= c->frame->size.top + c->frame->size.bottom; frame_frame_gravity(c->frame, &x, &y); /* get the client coords */ client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE); /* force it on screen if its moving to another monitor */ client_find_onscreen(c, &x, &y, w, h, mon != cmon); actions_client_move(data, TRUE); client_configure(c, x, y, w, h, TRUE, TRUE, FALSE); actions_client_move(data, FALSE); g_slice_free(Rect, area); g_slice_free(Rect, carea); } return FALSE; }
int main(int argc, char *argv[]) { if(argc != 2) { printf("usage : %s <ipaddress>\n", argv[0]); return -1; } strcpy(server_address, argv[1]); sleep_us(500000); /* * configure the client. */ if(client_configure(master_port, transmit_port, ssl_certificate, ssl_key) < 0) { printf("%-60s[\033[;31mFAILED\033[0m]\n", "client configured"); return -1; } printf("%-60s[\033[;32mOK\033[0m]\n", "client configured"); sleep_us(500000); /* * initialize the SSL */ ctx_server = ssl_server_init(ssl_certificate, ssl_key); if(ctx_server == NULL) { printf("%-60s[\033[;31mFAILED\033[0m]\n", "SSL server initialize"); return -1; } ctx_client = ssl_client_init(); if(ctx_client == NULL) { printf("%-60s[\033[;31mFAILED\033[0m]\n", "SSL client initialize"); return -1; } printf("%-60s[\033[;32mOK\033[0m]\n", "SSL initialize"); sleep_us(500000); /* * connect to the master server. */ char temp[MAXLINE]; snprintf(temp, MAXLINE, "connect to master server: %s", argv[1]); int masterfd = client_connect(argv[1], master_port); if(masterfd == -1) { printf("%-60s[\033[;31mFAILED\033[0m]\n", temp); return -1; } sockaddr_in clientaddr; socklen_t len = sizeof(clientaddr); memset(&clientaddr, 0, len); getsockname(masterfd, (sockaddr*)&clientaddr, &len); inet_ntop(AF_INET, (void *)&clientaddr.sin_addr, ip_address, MAXLINE); printf("%-60s[\033[;32mOK\033[0m]\n", temp); sleep_us(500000); SSL *ssl = ssl_client(ctx_client, masterfd); if(ssl == NULL) { printf("%-60s[\033[;31mFAILED\033[0m]\n", "ssl_client\n"); return -1; } /* * verify the executable client to judge if it's a fake one. */ char *ver_buf = file_verify(argv[0]); if(ver_buf == NULL) { printf("%-60s[\033[;31mFAILED\033[0m]\n", "verify client"); return -1; } int k = SSL_write(ssl, ver_buf, strlen(ver_buf)); if( k != (int)strlen(ver_buf)) { printf("SSL_write error\n"); return -1; } k = SSL_read(ssl, temp, MAXLINE); if(k < 0) { printf("SSL_read error"); return -1; } temp[k] = '\0'; if(strcmp(temp, "verify client unsuccessfully") == 0) { printf("%-60s[\033[;31mFAILED\033[0m]\n", "verify client"); return -1; } free(ver_buf); sleep_us(500000); /* * Listen to the transmit port to upload/download files */ snprintf(temp, MAXLINE, "listen to transmit port: %s", transmit_port); int listenfd = server_listen(transmit_port); if(listenfd == -1) { printf("%-60s[\033[;31mFAILED\033[0m]\n", temp); return -1; } printf("%-60s[\033[;32mOK\033[0m]\n", temp); sleep_us(500000); /* * create transmit_thread to handle upload/download files request * from the slave server. */ pthread_t thread; int ret = pthread_create(&thread, NULL, transmit_thread, static_cast<void*>(new int(listenfd))); if(ret == 0) printf("%-60s[\033[;32mOK\033[0m]\n", "transmit_thread create"); else { printf("%-60s[\033[;31FAILED\033[0m]\n", "transmit_thread create"); return -1; } /* * initialize the download/upload mutex. */ pthread_mutex_init(&download_mutex, NULL); pthread_mutex_init(&upload_mutex, NULL); char command_line[MAXLINE]; snprintf(cmd_line, MAXLINE,"%s:%s> ", argv[1], master_port); while(!stop) { printf(cmd_line); fflush(stdin); //read the command inputed by the user. fgets(command_line, MAXLINE, stdin); int len = strlen(command_line); if(command_line[len-1] == '\n') command_line[len-1] = '\0'; command_parse(ssl, command_line); } SSL_shutdown(ssl); // send SSL/TLS close_notify */ close(masterfd); SSL_free(ssl); SSL_CTX_free(ctx_server); SSL_CTX_free(ctx_client); return 0; }