Skip to content

Commit 79cc3b7

Browse files
committed
Refactor option setting code:
* Remove all duplicated display setters in switchres_manager. These are now set directly in the display_factory member, then passed later to individual display objects when they are created. * Implement sr_set_option api call, so now any configuration option that's available in inis can also be set programmatically by this call, e.g.: sr_set_option("dotclock_min", "25.0"); * Multi-monitor logic is preserved by means of sr_set_disp(), which tells Switchres which display to target in subsequent calls (like sr_set_option, etc.) Current display tracking has been moved to switchres_manager. * When a display is added, it is set as the current one with regards to subsequent calls. sr_set_disp(-1) can be called to point to the the display_factory one if needed.
1 parent c0abc6d commit 79cc3b7

11 files changed

+293
-287
lines changed

Diff for: display.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ display_manager *display_manager::make(display_settings *ds)
4646
display = new sdl2_display(ds);
4747
}
4848
catch (...) {};
49-
if ( ! display ) {
49+
if (!display)
50+
{
5051
#endif
5152

5253
#if defined(_WIN32)
@@ -103,6 +104,7 @@ void display_manager::parse_options()
103104
void display_manager::set_preset(const char *preset)
104105
{
105106
strncpy(m_ds.monitor, preset, sizeof(m_ds.monitor)-1);
107+
for (size_t i = 0; i < strlen(m_ds.monitor); i++) m_ds.monitor[i] = tolower(m_ds.monitor[i]);
106108

107109
memset(&range[0], 0, sizeof(struct monitor_range) * MAX_RANGES);
108110

@@ -521,3 +523,24 @@ bool display_manager::auto_specs()
521523

522524
return true;
523525
}
526+
527+
//============================================================
528+
// display_manager::get_aspect
529+
//============================================================
530+
531+
double display_manager::get_aspect(const char* aspect)
532+
{
533+
int num, den;
534+
if (sscanf(aspect, "%d:%d", &num, &den) == 2)
535+
{
536+
if (den == 0)
537+
{
538+
log_error("Error: denominator can't be zero\n");
539+
return STANDARD_CRT_ASPECT;
540+
}
541+
return (double(num)/double(den));
542+
}
543+
544+
log_error("Error: use format --aspect <num:den>\n");
545+
return STANDARD_CRT_ASPECT;
546+
}

Diff for: display.h

+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class display_manager
154154
void set_refresh_tolerance(double value) { m_ds.gs.refresh_tolerance = value; }
155155
void set_super_width(int value) { m_ds.gs.super_width = value; }
156156
void set_monitor_aspect(double value) { m_ds.gs.monitor_aspect = value; }
157+
void set_monitor_aspect(const char* aspect) { set_monitor_aspect(get_aspect(aspect)); }
157158
void set_h_size(double value) { m_ds.gs.h_size = value; }
158159
void set_h_shift(int value) { m_ds.gs.h_shift = value; }
159160
void set_v_shift(int value) { m_ds.gs.v_shift = value; }
@@ -209,6 +210,7 @@ class display_manager
209210
int m_id_counter = 0;
210211

211212
void set_preset(const char *preset);
213+
double get_aspect(const char* aspect);
212214

213215
protected:
214216
void* m_pf_data = nullptr;

Diff for: edid.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// edid_from_modeline
2323
//============================================================
2424

25-
int edid_from_modeline(modeline *mode, monitor_range *range, char *name, edid_block *edid)
25+
int edid_from_modeline(modeline *mode, monitor_range *range, const char *name, edid_block *edid)
2626
{
2727
if (!edid) return 0;
2828

Diff for: edid.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ typedef struct edid_block
3232
// PROTOTYPES
3333
//============================================================
3434

35-
int edid_from_modeline(modeline *mode, monitor_range *range, char *name, edid_block *edid);
35+
int edid_from_modeline(modeline *mode, monitor_range *range, const char *name, edid_block *edid);
3636

3737
#endif

Diff for: examples/multi_monitor.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ int main(int argc, char** argv)
1010
sr_init();
1111
sr_set_log_level(3);
1212

13+
sr_set_disp(-1);
1314
sr_set_monitor("arcade_31");
1415
sr_init_disp("0", NULL);
1516

17+
sr_set_disp(-1);
1618
sr_set_monitor("pc_31_120");
1719
sr_init_disp("1", NULL);
1820

Diff for: modeline.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ int modeline_parse(const char *user_modeline, modeline *mode)
622622

623623
if (e != 9)
624624
{
625-
log_error("SwitchRes: missing parameter in user modeline\n %s\n", user_modeline);
625+
log_error("Switchres: missing parameter in user modeline\n %s\n", user_modeline);
626626
memset(mode, 0, sizeof(struct modeline));
627627
return false;
628628
}
@@ -634,7 +634,7 @@ int modeline_parse(const char *user_modeline, modeline *mode)
634634
mode->refresh = mode->vfreq;
635635
mode->width = mode->hactive;
636636
mode->height = mode->vactive;
637-
log_verbose("SwitchRes: user modeline %s\n", modeline_print(mode, modeline_txt, MS_FULL));
637+
log_verbose("Switchres: user modeline %s\n", modeline_print(mode, modeline_txt, MS_FULL));
638638

639639
return true;
640640
}
@@ -645,11 +645,8 @@ int modeline_parse(const char *user_modeline, modeline *mode)
645645

646646
int modeline_to_monitor_range(monitor_range *range, modeline *mode)
647647
{
648-
if (range->vfreq_min == 0)
649-
{
650-
range->vfreq_min = mode->vfreq - 0.2;
651-
range->vfreq_max = mode->vfreq + 0.2;
652-
}
648+
range->vfreq_min = mode->vfreq - 0.2;
649+
range->vfreq_max = mode->vfreq + 0.2;
653650

654651
double line_time = 1 / mode->hfreq;
655652
double pixel_time = line_time / mode->htotal * 1000000;

0 commit comments

Comments
 (0)