diff --git a/helpers/auth_x11.c b/helpers/auth_x11.c index 5d6ff087..e9b2308a 100644 --- a/helpers/auth_x11.c +++ b/helpers/auth_x11.c @@ -455,8 +455,7 @@ const char *GetIndicators(int *warning, int *have_multiple_layouts) { have_output = 1; } - int i; - for (i = 0; i < XkbNumIndicators; i++) { + for (int i = 0; i < XkbNumIndicators; i++) { if (!(istate & (1U << i))) { continue; } @@ -495,8 +494,7 @@ const char *GetIndicators(int *warning, int *have_multiple_layouts) { } void DestroyPerMonitorWindows(size_t keep_windows) { - size_t i; - for (i = keep_windows; i < num_windows; ++i) { + for (size_t i = keep_windows; i < num_windows; ++i) { #ifdef HAVE_XFT_EXT XftDrawDestroy(xft_draws[i]); #endif @@ -618,8 +616,7 @@ void UpdatePerMonitorWindows(int monitors_changed, int region_w, int region_h, unsigned int unused_mask; XQueryPointer(display, parent_window, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &x, &y, &unused_mask); - size_t i; - for (i = 0; i < num_monitors; ++i) { + for (size_t i = 0; i < num_monitors; ++i) { if (x >= monitors[i].x && x < monitors[i].x + monitors[i].width && y >= monitors[i].y && y < monitors[i].y + monitors[i].height) { CreateOrUpdatePerMonitorWindow(0, &monitors[i], region_w, region_h, @@ -641,8 +638,7 @@ void UpdatePerMonitorWindows(int monitors_changed, int region_w, int region_h, size_t new_num_windows = num_monitors; // Update or create everything. - size_t i; - for (i = 0; i < new_num_windows; ++i) { + for (size_t i = 0; i < new_num_windows; ++i) { CreateOrUpdatePerMonitorWindow(i, &monitors[i], region_w, region_h, x_offset, y_offset); } @@ -875,8 +871,7 @@ void DisplayMessage(const char *title, const char *str, int is_warning) { x_offset, y_offset); per_monitor_windows_dirty = 0; - size_t i; - for (i = 0; i < num_windows; ++i) { + for (size_t i = 0; i < num_windows; ++i) { int cx = region_w / 2; int cy = region_h / 2; int y = cy + to - box_h / 2; @@ -1095,8 +1090,8 @@ int Prompt(const char *msg, char **response, int echo) { stride * DISCO_PASSWORD_DANCERS * strlen(disco_dancers[0]) + strlen(disco_combiner); - size_t i, bit; - for (i = 0, bit = 1; i < DISCO_PASSWORD_DANCERS; ++i, bit <<= 1) { + for (size_t i = 0, bit = 1; i < DISCO_PASSWORD_DANCERS; + ++i, bit <<= 1) { const char *dancer = disco_dancers[(priv.displaymarker & bit) ? 1 : 0]; memcpy(priv.displaybuf + i * stride, disco_combiner, @@ -1468,8 +1463,8 @@ enum PasswordPrompt GetPasswordPromptFromFlags( : PASSWORD_PROMPT_ASTERISKS; } - enum PasswordPrompt prompt; - for (prompt = 0; prompt < PASSWORD_PROMPT_COUNT; ++prompt) { + for (enum PasswordPrompt prompt = 0; prompt < PASSWORD_PROMPT_COUNT; + ++prompt) { if (strcmp(password_prompt_flag, PasswordPromptStrings[prompt]) == 0) { return prompt; } diff --git a/helpers/authproto_pam.c b/helpers/authproto_pam.c index de35730a..5ec575f5 100644 --- a/helpers/authproto_pam.c +++ b/helpers/authproto_pam.c @@ -84,15 +84,14 @@ int Converse(int num_msg, const struct pam_message **msg, *resp = calloc(num_msg, sizeof(struct pam_response)); - int i; - for (i = 0; i < num_msg; ++i) { + for (int i = 0; i < num_msg; ++i) { int status = ConverseOne(msg[i], &(*resp)[i]); if (status != PAM_SUCCESS) { - for (i = 0; i < num_msg; ++i) { - if ((*resp)[i].resp != NULL) { - explicit_bzero((*resp)[i].resp, strlen((*resp)[i].resp)); + for (int j = 0; j < num_msg; ++j) { + if ((*resp)[j].resp != NULL) { + explicit_bzero((*resp)[j].resp, strlen((*resp)[j].resp)); } - free((*resp)[i].resp); + free((*resp)[j].resp); } free(*resp); *resp = NULL; diff --git a/helpers/dimmer.c b/helpers/dimmer.c index 43129ce7..be0a8ed2 100644 --- a/helpers/dimmer.c +++ b/helpers/dimmer.c @@ -157,8 +157,7 @@ void DitherEffectDrawFrame(void *self, Display *display, Window dim_window, int start_pframe = frame * dimmer->pattern_frames / dimmer->super.frame_count; int end_pframe = (frame + 1) * dimmer->pattern_frames / dimmer->super.frame_count; - int pframe; - for (pframe = start_pframe; pframe < end_pframe; ++pframe) { + for (int pframe = start_pframe; pframe < end_pframe; ++pframe) { int x, y; Bayer(pframe, dimmer->pattern_power, &x, &y); XDrawPoint(display, dimmer->pattern, dimmer->pattern_gc, x, y); @@ -168,13 +167,12 @@ void DitherEffectDrawFrame(void *self, Display *display, Window dim_window, XChangeGC(display, dimmer->dim_gc, GCStipple, &dimmer->gc_values); // But do it in some sub-rectangles to be easier on the X server on large // screens. - int x, y; - for (y = 0; y < h; y += dimmer->max_fill_size) { + for (int y = 0; y < h; y += dimmer->max_fill_size) { int hh = h - y; if (hh > dimmer->max_fill_size) { hh = dimmer->max_fill_size; } - for (x = 0; x < w; x += dimmer->max_fill_size) { + for (int x = 0; x < w; x += dimmer->max_fill_size) { int ww = w - x; if (ww > dimmer->max_fill_size) { ww = dimmer->max_fill_size; @@ -376,8 +374,7 @@ int main(int argc, char **argv) { sleep_ts.tv_sec = sleep_time_ns / 1000000000; sleep_ts.tv_nsec = sleep_time_ns % 1000000000; XMapRaised(display, dim_window); - int i; - for (i = 0; i < dimmer->frame_count; ++i) { + for (int i = 0; i < dimmer->frame_count; ++i) { // Advance the dim pattern by one step. dimmer->DrawFrame(dimmer, display, dim_window, i, w, h); // Sleep a while. Yes, even at the end now - we want the user to see this diff --git a/helpers/monitors.c b/helpers/monitors.c index c099b539..4227f548 100644 --- a/helpers/monitors.c +++ b/helpers/monitors.c @@ -111,8 +111,7 @@ static void AddMonitor(Monitor* out_monitors, size_t* num_monitors, return; } // Skip overlapping "monitors" (typically in cloned display setups). - size_t i; - for (i = 0; i < *num_monitors; ++i) { + for (size_t i = 0; i < *num_monitors; ++i) { if (IntervalsOverlap(x, w, out_monitors[i].x, out_monitors[i].width) && IntervalsOverlap(y, h, out_monitors[i].y, out_monitors[i].height)) { #ifdef DEBUG_EVENTS @@ -139,8 +138,7 @@ static int GetMonitorsXRandR12(Display* dpy, Window window, int wx, int wy, if (screenres == NULL) { return 0; } - int i; - for (i = 0; i < screenres->noutput; ++i) { + for (int i = 0; i < screenres->noutput; ++i) { XRROutputInfo* output = XRRGetOutputInfo(dpy, screenres, screenres->outputs[i]); if (output == NULL) { @@ -182,8 +180,7 @@ static int GetMonitorsXRandR15(Display* dpy, Window window, int wx, int wy, if (rrmonitors == NULL) { return 0; } - int i; - for (i = 0; i < num_rrmonitors; ++i) { + for (int i = 0; i < num_rrmonitors; ++i) { XRRMonitorInfo* info = &rrmonitors[i]; int x = CLAMP(info->x, wx, wx + ww) - wx; int y = CLAMP(info->y, wy, wy + wh) - wy; @@ -233,8 +230,7 @@ static void GetMonitorsGuess(const XWindowAttributes* xwa, size_t guessed_monitors = CLAMP((size_t)(xwa->width * 9 + xwa->height * 8) / (size_t)(xwa->height * 16), // 1, max_monitors); - size_t i; - for (i = 0; i < guessed_monitors; ++i) { + for (size_t i = 0; i < guessed_monitors; ++i) { int x = xwa->width * i / guessed_monitors; int y = 0; int w = (xwa->width * (i + 1) / guessed_monitors) - diff --git a/helpers/saver_multiplex.c b/helpers/saver_multiplex.c index fb60eccb..95271847 100644 --- a/helpers/saver_multiplex.c +++ b/helpers/saver_multiplex.c @@ -50,8 +50,7 @@ static size_t num_monitors; static Window windows[MAX_MONITORS]; static void WatchSavers(void) { - size_t i; - for (i = 0; i < num_monitors; ++i) { + for (size_t i = 0; i < num_monitors; ++i) { WatchSaverChild(display, windows[i], i, saver_executable, 1); } } @@ -59,8 +58,7 @@ static void WatchSavers(void) { static void SpawnSavers(Window parent, int argc, char* const* argv) { XSetWindowAttributes attrs = {0}; attrs.background_pixel = BlackPixel(display, DefaultScreen(display)); - size_t i; - for (i = 0; i < num_monitors; ++i) { + for (size_t i = 0; i < num_monitors; ++i) { windows[i] = XCreateWindow(display, parent, monitors[i].x, monitors[i].y, monitors[i].width, monitors[i].height, 0, CopyFromParent, @@ -75,8 +73,7 @@ static void SpawnSavers(Window parent, int argc, char* const* argv) { } static void KillSavers(void) { - size_t i; - for (i = 0; i < num_monitors; ++i) { + for (size_t i = 0; i < num_monitors; ++i) { WatchSaverChild(display, windows[i], i, saver_executable, 0); XDestroyWindow(display, windows[i]); } diff --git a/helpers/until_nonidle.c b/helpers/until_nonidle.c index a288e78d..fae69561 100644 --- a/helpers/until_nonidle.c +++ b/helpers/until_nonidle.c @@ -81,8 +81,7 @@ uint64_t GetIdleTimeForSingleTimer(Display *display, Window w, } else { #ifdef HAVE_XSYNC_EXT if (have_xsync_ext) { - int i; - for (i = 0; i < num_xsync_counters; ++i) { + for (int i = 0; i < num_xsync_counters; ++i) { if (!strcmp(timer, xsync_counters[i].name)) { // I know this is inefficient. XSyncValue value; diff --git a/main.c b/main.c index b505c0bc..d9e90334 100644 --- a/main.c +++ b/main.c @@ -441,8 +441,7 @@ void LoadDefaults() { * Possible errors will be printed on stderr. */ void ParseArgumentsOrExit(int argc, char **argv) { - int i; - for (i = 1; i < argc; ++i) { + for (int i = 1; i < argc; ++i) { if (!strncmp(argv[i], "auth_", 5)) { Log("Setting auth child name from command line is DEPRECATED. Use " "the XSECURELOCK_AUTH environment variable instead"); @@ -983,8 +982,8 @@ int main(int argc, char **argv) { XIMPreeditNone | XIMStatusNothing, // Status might be invisible. XIMPreeditNone | XIMStatusNone // Standard handling. }; - size_t i; - for (i = 0; i < sizeof(input_styles) / sizeof(input_styles[0]); ++i) { + for (size_t i = 0; i < sizeof(input_styles) / sizeof(input_styles[0]); + ++i) { // Note: we draw XIM stuff in auth_window so it's above the saver/auth // child. However, we receive events for the grab window. xic = XCreateIC(xim, XNInputStyle, input_styles[i], XNClientWindow, @@ -1020,11 +1019,11 @@ int main(int argc, char **argv) { // Acquire all grabs we need. Retry in case the window manager is still // holding some grabs while starting XSecureLock. - int retries; int last_normal_attempt = force_grab ? 1 : 0; Window previous_focused_window = None; int previous_revert_focus_to = RevertToNone; - for (retries = 10; retries >= 0; --retries) { + int retries = 10; + for (; retries >= 0; --retries) { if (AcquireGrabs(display, root_window, my_windows, n_my_windows, transparent_cursor, /*silent=*/retries > last_normal_attempt, diff --git a/saver_child.c b/saver_child.c index 983f7478..d96cd2ca 100644 --- a/saver_child.c +++ b/saver_child.c @@ -30,8 +30,7 @@ static pid_t saver_child_pid[MAX_SAVERS] = {0}; void KillAllSaverChildrenSigHandler(int signo) { // This is a signal handler, so we're not going to make this too // complicated. Just kill 'em all. - int i; - for (i = 0; i < MAX_SAVERS; ++i) { + for (int i = 0; i < MAX_SAVERS; ++i) { if (saver_child_pid[i] != 0) { KillPgrp(saver_child_pid[i], signo); } diff --git a/unmap_all.c b/unmap_all.c index db3a91cf..ed0d1c22 100644 --- a/unmap_all.c +++ b/unmap_all.c @@ -21,8 +21,7 @@ int InitUnmapAllWindowsState(UnmapAllWindowsState* state, Display* display, XQueryTree(state->display, state->root_window, &unused_root_return, &unused_parent_return, &state->windows, &state->n_windows); state->first_unmapped_window = state->n_windows; // That means none unmapped. - unsigned int i; - for (i = 0; i < state->n_windows; ++i) { + for (unsigned int i = 0; i < state->n_windows; ++i) { XWindowAttributes xwa; XGetWindowAttributes(display, state->windows[i], &xwa); // Not mapped -> nothing to do. @@ -36,8 +35,7 @@ int InitUnmapAllWindowsState(UnmapAllWindowsState* state, Display* display, state->windows[i] = XmuClientWindow(display, state->windows[i]); } // If any window we'd be unmapping is in the ignore list, skip it. - unsigned int j; - for (j = 0; j < n_ignored_windows; ++j) { + for (unsigned int j = 0; j < n_ignored_windows; ++j) { if (state->windows[i] == ignored_windows[j]) { state->windows[i] = None; } @@ -76,8 +74,8 @@ int UnmapAllWindows(UnmapAllWindowsState* state, if (state->first_unmapped_window == 0) { // Already all unmapped. return 0; } - unsigned int i; - for (i = state->first_unmapped_window - 1;; --i) { // Top-to-bottom order! + for (unsigned int i = state->first_unmapped_window - 1;; + --i) { // Top-to-bottom order! if (state->windows[i] != None) { XUnmapWindow(state->display, state->windows[i]); state->first_unmapped_window = i; @@ -94,8 +92,8 @@ int UnmapAllWindows(UnmapAllWindowsState* state, } void RemapAllWindows(UnmapAllWindowsState* state) { - unsigned int i; - for (i = state->first_unmapped_window; i < state->n_windows; ++i) { + for (unsigned int i = state->first_unmapped_window; i < state->n_windows; + ++i) { if (state->windows[i] != None) { XMapWindow(state->display, state->windows[i]); }