Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2020-10-18 00:36:02 +0300
committerHans Goudey <h.goudey@me.com>2020-10-18 00:36:02 +0300
commitf425f40c4e17e889c720647b26c07ae3f6d3ba64 (patch)
treeb8b42d0862def239c0a05d2b3cae452aba68464d /source/blender/windowmanager/intern/wm_window.c
parent85e78fa17cd54676b5aa9a15a0b885b4a7187086 (diff)
Cleanup: More miscellaneous code quality changes in wm directory
- Declare variables where initialized. - Use LISTBASE_FOREACH macro. - Reduce variable scope. - Return early or reduce indentation in some cases.
Diffstat (limited to 'source/blender/windowmanager/intern/wm_window.c')
-rw-r--r--source/blender/windowmanager/intern/wm_window.c247
1 files changed, 106 insertions, 141 deletions
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 8db8694e8a6..6782d8ea484 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -162,8 +162,7 @@ void wm_get_desktopsize(int *r_width, int *r_height)
/* XXX solve dual screen... */
static void wm_window_check_position(rcti *rect)
{
- int width, height, d;
-
+ int width, height;
wm_get_screensize(&width, &height);
if (rect->xmin < 0) {
@@ -175,12 +174,12 @@ static void wm_window_check_position(rcti *rect)
rect->ymin = 0;
}
if (rect->xmax > width) {
- d = rect->xmax - width;
+ int d = rect->xmax - width;
rect->xmax -= d;
rect->xmin -= d;
}
if (rect->ymax > height) {
- d = rect->ymax - height;
+ int d = rect->ymax - height;
rect->ymax -= d;
rect->ymin -= d;
}
@@ -223,8 +222,6 @@ static void wm_ghostwindow_destroy(wmWindowManager *wm, wmWindow *win)
* ED_screen_exit should have been called */
void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win)
{
- wmTimer *wt, *wtnext;
-
/* update context */
if (C) {
WM_event_remove_handlers(C, &win->handlers);
@@ -238,16 +235,14 @@ void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win)
BKE_screen_area_map_free(&win->global_areas);
/* end running jobs, a job end also removes its timer */
- for (wt = wm->timers.first; wt; wt = wtnext) {
- wtnext = wt->next;
+ LISTBASE_FOREACH_MUTABLE (wmTimer *, wt, &wm->timers) {
if (wt->win == win && wt->event_type == TIMERJOBS) {
wm_jobs_timer_ended(wm, wt);
}
}
/* timer removing, need to call this api function */
- for (wt = wm->timers.first; wt; wt = wtnext) {
- wtnext = wt->next;
+ LISTBASE_FOREACH_MUTABLE (wmTimer *, wt, &wm->timers) {
if (wt->win == win) {
WM_event_remove_timer(wm, win, wt);
}
@@ -275,10 +270,9 @@ void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win)
static int find_free_winid(wmWindowManager *wm)
{
- wmWindow *win;
int id = 1;
- for (win = wm->windows.first; win; win = win->next) {
+ LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
if (id <= win->winid) {
id = win->winid + 1;
}
@@ -314,7 +308,6 @@ wmWindow *wm_window_copy(Main *bmain,
wmWindow *win_dst = wm_window_new(bmain, wm, win_parent, is_dialog);
WorkSpace *workspace = WM_window_get_active_workspace(win_src);
WorkSpaceLayout *layout_old = WM_window_get_active_layout(win_src);
- WorkSpaceLayout *layout_new;
win_dst->posx = win_src->posx + 10;
win_dst->posy = win_src->posy;
@@ -324,9 +317,9 @@ wmWindow *wm_window_copy(Main *bmain,
win_dst->scene = win_src->scene;
STRNCPY(win_dst->view_layer_name, win_src->view_layer_name);
BKE_workspace_active_set(win_dst->workspace_hook, workspace);
- layout_new = duplicate_layout ?
- ED_workspace_layout_duplicate(bmain, workspace, layout_old, win_dst) :
- layout_old;
+ WorkSpaceLayout *layout_new = duplicate_layout ? ED_workspace_layout_duplicate(
+ bmain, workspace, layout_old, win_dst) :
+ layout_old;
BKE_workspace_active_layout_set(win_dst->workspace_hook, win_dst->winid, workspace, layout_new);
*win_dst->stereo3d_format = *win_src->stereo3d_format;
@@ -345,9 +338,8 @@ wmWindow *wm_window_copy_test(bContext *C,
{
Main *bmain = CTX_data_main(C);
wmWindowManager *wm = CTX_wm_manager(C);
- wmWindow *win_dst;
- win_dst = wm_window_copy(bmain, wm, win_src, duplicate_layout, child);
+ wmWindow *win_dst = wm_window_copy(bmain, wm, win_src, duplicate_layout, child);
WM_check(C);
@@ -568,11 +560,9 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm,
wmWindow *win,
bool is_dialog)
{
- GHOST_WindowHandle ghostwin;
- GHOST_GLSettings glSettings = {0};
- int scr_w, scr_h, posy;
/* a new window is created when pageflip mode is required for a window */
+ GHOST_GLSettings glSettings = {0};
if (win->stereo3d_format->display_mode == S3D_DISPLAY_PAGEFLIP) {
glSettings.flags |= GHOST_glStereoVisual;
}
@@ -581,13 +571,15 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm,
glSettings.flags |= GHOST_glDebugContext;
}
+ int scr_w, scr_h;
wm_get_screensize(&scr_w, &scr_h);
- posy = (scr_h - win->posy - win->sizey);
+ int posy = (scr_h - win->posy - win->sizey);
/* Clear drawable so we can set the new window. */
wmWindow *prev_windrawable = wm->windrawable;
wm_window_clear_drawable(wm);
+ GHOST_WindowHandle ghostwin;
if (is_dialog && win->parent) {
ghostwin = GHOST_CreateDialogWindow(g_system,
win->parent->ghostwin,
@@ -613,8 +605,6 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm,
}
if (ghostwin) {
- GHOST_RectangleHandle bounds;
-
win->gpuctx = GPU_context_create(ghostwin);
/* needed so we can detect the graphics card below */
@@ -630,7 +620,7 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm,
wm_window_ensure_eventstate(win);
/* store actual window size in blender window */
- bounds = GHOST_GetClientBounds(win->ghostwin);
+ GHOST_RectangleHandle bounds = GHOST_GetClientBounds(win->ghostwin);
/* win32: gives undefined window size when minimized */
if (GHOST_GetWindowState(win->ghostwin) != GHOST_kWindowStateMinimized) {
@@ -662,8 +652,6 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm,
static void wm_window_ghostwindow_ensure(wmWindowManager *wm, wmWindow *win, bool is_dialog)
{
- wmKeyMap *keymap;
-
if (win->ghostwin == NULL) {
if ((win->sizex == 0) || (wm_init_state.override_flag & WIN_OVERRIDE_GEOM)) {
win->posx = wm_init_state.start_x;
@@ -704,7 +692,7 @@ static void wm_window_ghostwindow_ensure(wmWindowManager *wm, wmWindow *win, boo
}
/* add keymap handlers (1 handler for all keys in map!) */
- keymap = WM_keymap_ensure(wm->defaultconf, "Window", 0, 0);
+ wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Window", 0, 0);
WM_event_add_keymap_handler(&win->handlers, keymap);
keymap = WM_keymap_ensure(wm->defaultconf, "Screen", 0, 0);
@@ -766,12 +754,9 @@ void wm_window_ghostwindows_ensure(wmWindowManager *wm)
*/
void wm_window_ghostwindows_remove_invalid(bContext *C, wmWindowManager *wm)
{
- wmWindow *win, *win_next;
-
BLI_assert(G.background == false);
- for (win = wm->windows.first; win; win = win_next) {
- win_next = win->next;
+ LISTBASE_FOREACH_MUTABLE (wmWindow *, win, &wm->windows) {
if (win->ghostwin == NULL) {
wm_window_close(C, wm, win);
}
@@ -781,20 +766,18 @@ void wm_window_ghostwindows_remove_invalid(bContext *C, wmWindowManager *wm)
/* Update window size and position based on data from GHOST window. */
static bool wm_window_update_size_position(wmWindow *win)
{
- GHOST_RectangleHandle client_rect;
- int l, t, r, b, scr_w, scr_h;
- int sizex, sizey, posx, posy;
-
- client_rect = GHOST_GetClientBounds(win->ghostwin);
+ GHOST_RectangleHandle client_rect = GHOST_GetClientBounds(win->ghostwin);
+ int l, t, r, b;
GHOST_GetRectangle(client_rect, &l, &t, &r, &b);
GHOST_DisposeRectangle(client_rect);
+ int scr_w, scr_h;
wm_get_desktopsize(&scr_w, &scr_h);
- sizex = r - l;
- sizey = b - t;
- posx = l;
- posy = scr_h - t - win->sizey;
+ int sizex = r - l;
+ int sizey = b - t;
+ int posx = l;
+ int posy = scr_h - t - win->sizey;
if (win->sizex != sizex || win->sizey != sizey || win->posx != posx || win->posy != posy) {
win->sizex = sizex;
@@ -853,9 +836,6 @@ wmWindow *WM_window_open_temp(bContext *C,
Main *bmain = CTX_data_main(C);
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win_prev = CTX_wm_window(C);
- wmWindow *win;
- bScreen *screen;
- ScrArea *area;
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
@@ -878,9 +858,11 @@ wmWindow *WM_window_open_temp(bContext *C,
/* Reuse temporary or dialog window if one is open (but don't use a dialog for a regular
* temporary window, or vice versa). */
- for (win = wm->windows.first; win; win = win->next) {
- if (WM_window_is_temp_screen(win) && (dialog == GHOST_IsDialogWindow(win->ghostwin))) {
- break;
+ wmWindow *win = NULL;
+ LISTBASE_FOREACH (wmWindow *, win_iter, &wm->windows) {
+ if (WM_window_is_temp_screen(win_iter) &&
+ (dialog == GHOST_IsDialogWindow(win_iter->ghostwin))) {
+ win = win_iter;
}
}
@@ -892,7 +874,7 @@ wmWindow *WM_window_open_temp(bContext *C,
win->posy = rect.ymin;
}
- screen = WM_window_get_active_screen(win);
+ bScreen *screen = WM_window_get_active_screen(win);
win->sizex = BLI_rcti_size_x(&rect);
win->sizey = BLI_rcti_size_y(&rect);
@@ -934,7 +916,7 @@ wmWindow *WM_window_open_temp(bContext *C,
*/
/* ensure it shows the right spacetype editor */
- area = screen->areabase.first;
+ ScrArea *area = screen->areabase.first;
CTX_wm_area_set(C, area);
ED_area_newspace(C, area, space_type, false);
@@ -977,9 +959,8 @@ int wm_window_close_exec(bContext *C, wmOperator *UNUSED(op))
int wm_window_new_exec(bContext *C, wmOperator *UNUSED(op))
{
wmWindow *win_src = CTX_wm_window(C);
- bool ok;
- ok = (wm_window_copy_test(C, win_src, true, true) != NULL);
+ bool ok = (wm_window_copy_test(C, win_src, true, true) != NULL);
return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@@ -987,9 +968,8 @@ int wm_window_new_exec(bContext *C, wmOperator *UNUSED(op))
int wm_window_new_main_exec(bContext *C, wmOperator *UNUSED(op))
{
wmWindow *win_src = CTX_wm_window(C);
- bool ok;
- ok = (wm_window_copy_test(C, win_src, true, false) != NULL);
+ bool ok = (wm_window_copy_test(C, win_src, true, false) != NULL);
return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@@ -998,13 +978,12 @@ int wm_window_new_main_exec(bContext *C, wmOperator *UNUSED(op))
int wm_window_fullscreen_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
wmWindow *window = CTX_wm_window(C);
- GHOST_TWindowState state;
if (G.background) {
return OPERATOR_CANCELLED;
}
- state = GHOST_GetWindowState(window->ghostwin);
+ GHOST_TWindowState state = GHOST_GetWindowState(window->ghostwin);
if (state != GHOST_kWindowStateFullScreen) {
GHOST_SetWindowState(window->ghostwin, GHOST_kWindowStateFullScreen);
}
@@ -1061,8 +1040,6 @@ typedef enum {
static int query_qual(modifierKeyType qual)
{
GHOST_TModifierKeyMask left, right;
- int val = 0;
-
switch (qual) {
case SHIFT:
left = GHOST_kModifierKeyLeftShift;
@@ -1082,6 +1059,7 @@ static int query_qual(modifierKeyType qual)
break;
}
+ int val = 0;
GHOST_GetModifierKeyState(g_system, left, &val);
if (!val) {
GHOST_GetModifierKeyState(g_system, right, &val);
@@ -1163,8 +1141,8 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
if (type == GHOST_kEventQuitRequest) {
/* Find an active window to display quit dialog in. */
GHOST_WindowHandle ghostwin = GHOST_GetEventWindow(evt);
- wmWindow *win;
+ wmWindow *win;
if (ghostwin && GHOST_ValidWindow(g_system, ghostwin)) {
win = GHOST_GetWindowUserData(ghostwin);
}
@@ -1183,7 +1161,6 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
else {
GHOST_WindowHandle ghostwin = GHOST_GetEventWindow(evt);
GHOST_TEventDataPtr data = GHOST_GetEventData(evt);
- wmWindow *win;
/* Ghost now can call this function for life resizes,
* but it should return if WM didn't initialize yet.
@@ -1203,7 +1180,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
puts("<!> event has invalid window");
return 1;
}
- win = GHOST_GetWindowUserData(ghostwin);
+ wmWindow *win = GHOST_GetWindowUserData(ghostwin);
switch (type) {
case GHOST_kEventWindowDeactivate:
@@ -1220,7 +1197,6 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
break;
case GHOST_kEventWindowActivate: {
GHOST_TEventKeyData kdata;
- wmEvent event;
const int keymodifier = ((query_qual(SHIFT) ? KM_SHIFT : 0) |
(query_qual(CONTROL) ? KM_CTRL : 0) |
(query_qual(ALT) ? KM_ALT : 0) | (query_qual(OS) ? KM_OSKEY : 0));
@@ -1320,6 +1296,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
* currently it seems to be common practice to generate new event for, but probably
* we'll need utility function for this? (sergey)
*/
+ wmEvent event;
wm_event_init_from_window(win, &event);
event.type = MOUSEMOVE;
event.prevx = event.x;
@@ -1345,8 +1322,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
}
case GHOST_kEventWindowSize:
case GHOST_kEventWindowMove: {
- GHOST_TWindowState state;
- state = GHOST_GetWindowState(win->ghostwin);
+ GHOST_TWindowState state = GHOST_GetWindowState(win->ghostwin);
win->windowstate = state;
WM_window_set_dpi(win);
@@ -1424,7 +1400,6 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
}
case GHOST_kEventOpenMainFile: {
- PointerRNA props_ptr;
const char *path = GHOST_GetEventData(evt);
if (path) {
@@ -1433,6 +1408,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
* it is correctly set */
CTX_wm_window_set(C, win);
+ PointerRNA props_ptr;
WM_operator_properties_create_ptr(&props_ptr, ot);
RNA_string_set(&props_ptr, "filepath", path);
RNA_boolean_set(&props_ptr, "display_file_selector", false);
@@ -1444,12 +1420,12 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
break;
}
case GHOST_kEventDraggingDropDone: {
- wmEvent event;
GHOST_TEventDragnDropData *ddd = GHOST_GetEventData(evt);
/* entering window, update mouse pos */
wm_window_update_eventstate(win);
+ wmEvent event;
wm_event_init_from_window(win, &event); /* copy last state, like mouse coords */
/* activate region */
@@ -1479,12 +1455,11 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
if (ddd->dataType == GHOST_kDragnDropTypeFilenames) {
GHOST_TStringArray *stra = ddd->data;
- int a, icon;
- for (a = 0; a < stra->count; a++) {
+ for (int a = 0; a < stra->count; a++) {
printf("drop file %s\n", stra->strings[a]);
/* try to get icon type from extension */
- icon = ED_file_extension_icon((char *)stra->strings[a]);
+ int icon = ED_file_extension_icon((char *)stra->strings[a]);
WM_event_start_drag(C, icon, WM_DRAG_PATH, stra->strings[a], 0.0, WM_DRAG_NOP);
/* void poin should point to string, it makes a copy */
@@ -1560,44 +1535,44 @@ static int wm_window_timer(const bContext *C)
{
Main *bmain = CTX_data_main(C);
wmWindowManager *wm = CTX_wm_manager(C);
- wmTimer *wt, *wtnext;
- wmWindow *win;
double time = PIL_check_seconds_timer();
int retval = 0;
- for (wt = wm->timers.first; wt; wt = wtnext) {
- wtnext = wt->next; /* in case timer gets removed */
- win = wt->win;
+ /* Mutable in case the timer gets removed. */
+ LISTBASE_FOREACH_MUTABLE (wmTimer *, wt, &wm->timers) {
+ wmWindow *win = wt->win;
- if (wt->sleep == 0) {
- if (time > wt->ntime) {
- wt->delta = time - wt->ltime;
- wt->duration += wt->delta;
- wt->ltime = time;
- wt->ntime = wt->stime + wt->timestep * ceil(wt->duration / wt->timestep);
+ if (wt->sleep != 0) {
+ continue;
+ }
- if (wt->event_type == TIMERJOBS) {
- wm_jobs_timer(wm, wt);
- }
- else if (wt->event_type == TIMERAUTOSAVE) {
- wm_autosave_timer(bmain, wm, wt);
- }
- else if (wt->event_type == TIMERNOTIFIER) {
- WM_main_add_notifier(POINTER_AS_UINT(wt->customdata), NULL);
- }
- else if (win) {
- wmEvent event;
- wm_event_init_from_window(win, &event);
-
- event.type = wt->event_type;
- event.val = KM_NOTHING;
- event.keymodifier = 0;
- event.custom = EVT_DATA_TIMER;
- event.customdata = wt;
- wm_event_add(win, &event);
-
- retval = 1;
- }
+ if (time > wt->ntime) {
+ wt->delta = time - wt->ltime;
+ wt->duration += wt->delta;
+ wt->ltime = time;
+ wt->ntime = wt->stime + wt->timestep * ceil(wt->duration / wt->timestep);
+
+ if (wt->event_type == TIMERJOBS) {
+ wm_jobs_timer(wm, wt);
+ }
+ else if (wt->event_type == TIMERAUTOSAVE) {
+ wm_autosave_timer(bmain, wm, wt);
+ }
+ else if (wt->event_type == TIMERNOTIFIER) {
+ WM_main_add_notifier(POINTER_AS_UINT(wt->customdata), NULL);
+ }
+ else if (win) {
+ wmEvent event;
+ wm_event_init_from_window(win, &event);
+
+ event.type = wt->event_type;
+ event.val = KM_NOTHING;
+ event.keymodifier = 0;
+ event.custom = EVT_DATA_TIMER;
+ event.customdata = wt;
+ wm_event_add(win, &event);
+
+ retval = 1;
}
}
}
@@ -1606,11 +1581,9 @@ static int wm_window_timer(const bContext *C)
void wm_window_process_events(const bContext *C)
{
- int hasevent;
-
BLI_assert(BLI_thread_is_main());
- hasevent = GHOST_ProcessEvents(g_system, 0); /* 0 is no wait */
+ int hasevent = GHOST_ProcessEvents(g_system, 0); /* 0 is no wait */
if (hasevent) {
GHOST_DispatchEvents(g_system);
@@ -1680,17 +1653,12 @@ void WM_event_timer_sleep(wmWindowManager *wm,
wmTimer *timer,
bool do_sleep)
{
- wmTimer *wt;
-
- for (wt = wm->timers.first; wt; wt = wt->next) {
+ LISTBASE_FOREACH (wmTimer *, wt, &wm->timers) {
if (wt == timer) {
+ wt->sleep = do_sleep;
break;
}
}
-
- if (wt) {
- wt->sleep = do_sleep;
- }
}
wmTimer *WM_event_add_timer(wmWindowManager *wm, wmWindow *win, int event_type, double timestep)
@@ -1732,35 +1700,33 @@ wmTimer *WM_event_add_timer_notifier(wmWindowManager *wm,
void WM_event_remove_timer(wmWindowManager *wm, wmWindow *UNUSED(win), wmTimer *timer)
{
- wmTimer *wt;
-
/* extra security check */
- for (wt = wm->timers.first; wt; wt = wt->next) {
- if (wt == timer) {
- break;
+ wmTimer *wt = NULL;
+ LISTBASE_FOREACH (wmTimer *, timer_iter, &wm->timers) {
+ if (timer_iter == timer) {
+ wt = timer_iter;
}
}
- if (wt) {
- wmWindow *win;
+ if (wt == NULL) {
+ return;
+ }
- if (wm->reports.reporttimer == wt) {
- wm->reports.reporttimer = NULL;
- }
+ if (wm->reports.reporttimer == wt) {
+ wm->reports.reporttimer = NULL;
+ }
- BLI_remlink(&wm->timers, wt);
- if (wt->customdata != NULL && (wt->flags & WM_TIMER_NO_FREE_CUSTOM_DATA) == 0) {
- MEM_freeN(wt->customdata);
- }
- MEM_freeN(wt);
-
- /* there might be events in queue with this timer as customdata */
- for (win = wm->windows.first; win; win = win->next) {
- wmEvent *event;
- for (event = win->queue.first; event; event = event->next) {
- if (event->customdata == wt) {
- event->customdata = NULL;
- event->type = EVENT_NONE; /* timer users customdata, dont want NULL == NULL */
- }
+ BLI_remlink(&wm->timers, wt);
+ if (wt->customdata != NULL && (wt->flags & WM_TIMER_NO_FREE_CUSTOM_DATA) == 0) {
+ MEM_freeN(wt->customdata);
+ }
+ MEM_freeN(wt);
+
+ /* there might be events in queue with this timer as customdata */
+ LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
+ LISTBASE_FOREACH (wmEvent *, event, &win->queue) {
+ if (event->customdata == wt) {
+ event->customdata = NULL;
+ event->type = EVENT_NONE; /* timer users customdata, dont want NULL == NULL */
}
}
}
@@ -1780,25 +1746,24 @@ void WM_event_remove_timer_notifier(wmWindowManager *wm, wmWindow *win, wmTimer
static char *wm_clipboard_text_get_ex(bool selection, int *r_len, bool firstline)
{
- char *p, *p2, *buf, *newbuf;
-
if (G.background) {
*r_len = 0;
return NULL;
}
- buf = (char *)GHOST_getClipboard(selection);
+ char *buf = (char *)GHOST_getClipboard(selection);
if (!buf) {
*r_len = 0;
return NULL;
}
/* always convert from \r\n to \n */
- p2 = newbuf = MEM_mallocN(strlen(buf) + 1, __func__);
+ char *newbuf = MEM_mallocN(strlen(buf) + 1, __func__);
+ char *p2 = newbuf;
if (firstline) {
/* will return an over-alloc'ed value in the case there are newlines */
- for (p = buf; *p; p++) {
+ for (char *p = buf; *p; p++) {
if ((*p != '\n') && (*p != '\r')) {
*(p2++) = *p;
}
@@ -1808,7 +1773,7 @@ static char *wm_clipboard_text_get_ex(bool selection, int *r_len, bool firstline
}
}
else {
- for (p = buf; *p; p++) {
+ for (char *p = buf; *p; p++) {
if (*p != '\r') {
*(p2++) = *p;
}