summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-11-07 13:52:31 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-11-07 13:53:27 +0900
commit6a47c2243e604e44461ae915476f50d00eeafdf6 (patch)
treea84f58e62727f65c9a24971107425349641f7191
parentee93543799fc4ccf72a0cbf43a2c3efe5c61d6d3 (diff)
efl ui win - make win centering work with multiple screens
this should fix T6323 @fix
-rw-r--r--src/lib/elementary/efl_ui_win.c46
-rw-r--r--src/modules/ecore_evas/engines/x/ecore_evas_x.c96
2 files changed, 121 insertions, 21 deletions
diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c
index 4904a13e10..87e7e9624d 100644
--- a/src/lib/elementary/efl_ui_win.c
+++ b/src/lib/elementary/efl_ui_win.c
@@ -5595,6 +5595,52 @@ _efl_ui_win_center(Eo *obj, Efl_Ui_Win_Data *sd, Eina_Bool h, Eina_Bool v)
5595 if ((trap) && (trap->center) && (!trap->center(sd->trap_data, obj, h, v))) 5595 if ((trap) && (trap->center) && (!trap->center(sd->trap_data, obj, h, v)))
5596 return; 5596 return;
5597 5597
5598 if (!efl_gfx_visible_get(obj))
5599 {
5600 // Chose to use env var so this will also translate more easily
5601 // to wayland. yes - we can get x atoms to figure out if wm is
5602 // enlightenment, but this works just as well. for wl we'd need
5603 // an alternate wl specific way... this below works better IMHO
5604 const char *s = getenv("DESKTOP");
5605
5606 if ((s) && (!strcasecmp(s, "Enlightenment")))
5607 {
5608#ifdef HAVE_ELEMENTARY_X
5609 if (sd->x.xwin)
5610 {
5611 static Ecore_X_Atom state = 0;
5612 static Ecore_X_Atom centered = 0;
5613
5614 if (!centered) centered = ecore_x_atom_get
5615 ("__E_ATOM_WINDOW_STATE_CENTERED");
5616 if (!state) state = ecore_x_atom_get
5617 ("__E_ATOM_WINDOW_STATE");
5618 ecore_x_window_prop_card32_set(sd->x.xwin, state, &centered, 1);
5619 }
5620#endif
5621// XXX: what to do with wayland?
5622 return;
5623 }
5624 // not e - fall back to manually placing on what we think the screen
5625 // is/will be... to do this move window to where pointer is first
5626#ifdef HAVE_ELEMENTARY_X
5627 if (sd->x.xwin)
5628 {
5629 int x = 0, y = 0;
5630
5631 if (sd->req_wh)
5632 {
5633 win_w = sd->req_w;
5634 win_h = sd->req_h;
5635 }
5636 else evas_object_geometry_get(obj, NULL, NULL, &win_w, &win_h);
5637 ecore_x_pointer_root_xy_get(&x, &y);
5638 ecore_evas_move(sd->ee, x - (win_w / 2), y - (win_h / 2));
5639 }
5640#endif
5641// XXX: what to do with wayland?
5642 }
5643
5598 ecore_evas_screen_geometry_get(sd->ee, 5644 ecore_evas_screen_geometry_get(sd->ee,
5599 &screen_x, &screen_y, 5645 &screen_x, &screen_y,
5600 &screen_w, &screen_h); 5646 &screen_w, &screen_h);
diff --git a/src/modules/ecore_evas/engines/x/ecore_evas_x.c b/src/modules/ecore_evas/engines/x/ecore_evas_x.c
index 542b3f82e9..88779a2a7c 100644
--- a/src/modules/ecore_evas/engines/x/ecore_evas_x.c
+++ b/src/modules/ecore_evas/engines/x/ecore_evas_x.c
@@ -3478,15 +3478,16 @@ _ecore_evas_x_avoid_damage_set(Ecore_Evas *ee, int on)
3478} 3478}
3479 3479
3480static void 3480static void
3481_ecore_evas_x_screen_geometry_get(const Ecore_Evas *ee EINA_UNUSED, int *x, int *y, int *w, int *h) 3481_ecore_evas_x_screen_geometry_get(const Ecore_Evas *ee, int *x, int *y, int *w, int *h)
3482{ 3482{
3483 int outnum = 0; 3483 int outnum = 0, i;
3484 int px = 0, py = 0, pw = 0, ph = 0; 3484 int px = 0, py = 0, pw = 0, ph = 0;
3485 Ecore_X_Window root; 3485 Ecore_X_Window root;
3486 Ecore_X_Randr_Output *out = NULL; 3486 Ecore_X_Randr_Output *out = NULL;
3487 Ecore_X_Randr_Crtc crtc; 3487 Ecore_X_Randr_Crtc crtc;
3488 unsigned int val[4] = { 0 }; 3488 unsigned int val[4] = { 0 };
3489 3489 Eina_Bool found = EINA_FALSE;
3490
3490 if (ecore_x_window_prop_card32_get 3491 if (ecore_x_window_prop_card32_get
3491 (ee->prop.window, ecore_x_atom_get("E_ZONE_GEOMETRY"), val, 4) == 4) 3492 (ee->prop.window, ecore_x_atom_get("E_ZONE_GEOMETRY"), val, 4) == 4)
3492 { 3493 {
@@ -3496,7 +3497,7 @@ _ecore_evas_x_screen_geometry_get(const Ecore_Evas *ee EINA_UNUSED, int *x, int
3496 if (h) *h = (int)val[3]; 3497 if (h) *h = (int)val[3];
3497 return; 3498 return;
3498 } 3499 }
3499 3500
3500 root = ecore_x_window_root_get(ee->prop.window); 3501 root = ecore_x_window_root_get(ee->prop.window);
3501 out = ecore_x_randr_window_outputs_get(ee->prop.window, &outnum); 3502 out = ecore_x_randr_window_outputs_get(ee->prop.window, &outnum);
3502 if (!out) 3503 if (!out)
@@ -3508,25 +3509,53 @@ norandr:
3508 ecore_x_window_size_get(root, w, h); 3509 ecore_x_window_size_get(root, w, h);
3509 return; 3510 return;
3510 } 3511 }
3511 crtc = ecore_x_randr_output_crtc_get(root, out[0]); 3512 for (i = 0; i < outnum; i++)
3512 if (!crtc) goto norandr; 3513 {
3513 ecore_x_randr_crtc_geometry_get(root, crtc, &px, &py, &pw, &ph); 3514 Eina_Rectangle winrect, outrect;
3514 if ((pw == 0) || (ph == 0)) goto norandr; 3515
3515 if (x) *x = px; 3516 crtc = ecore_x_randr_output_crtc_get(root, out[i]);
3516 if (y) *y = py; 3517 if (!crtc) continue;
3517 if (w) *w = pw; 3518 ecore_x_randr_crtc_geometry_get(root, crtc, &px, &py, &pw, &ph);
3518 if (h) *h = ph; 3519 if ((pw == 0) || (ph == 0)) continue;
3520 if ((i == 0) || (ecore_x_randr_primary_output_get(root) == out[i]))
3521 {
3522 found = EINA_TRUE;
3523 if (x) *x = px;
3524 if (y) *y = py;
3525 if (w) *w = pw;
3526 if (h) *h = ph;
3527 }
3528 winrect.x = ee->x + (ee->w / 2);
3529 winrect.y = ee->y + (ee->h / 2);
3530 winrect.w = 1;
3531 winrect.h = 1;
3532 outrect.x = px;
3533 outrect.y = py;
3534 outrect.w = pw;
3535 outrect.h = ph;
3536 if (eina_rectangles_intersect(&outrect, &winrect))
3537 {
3538 if (x) *x = px;
3539 if (y) *y = py;
3540 if (w) *w = pw;
3541 if (h) *h = ph;
3542 free(out);
3543 return;
3544 }
3545 }
3519 free(out); 3546 free(out);
3547 if (!found) goto norandr;
3520} 3548}
3521 3549
3522static void 3550static void
3523_ecore_evas_x_screen_dpi_get(const Ecore_Evas *ee, int *xdpi, int *ydpi) 3551_ecore_evas_x_screen_dpi_get(const Ecore_Evas *ee, int *xdpi, int *ydpi)
3524{ 3552{
3525 int scdpi, xmm = 0, ymm = 0, outnum = 0, w = 0, h = 0; 3553 int scdpi, xmm = 0, ymm = 0, outnum = 0, w = 0, h = 0;
3526 int px = 0, py = 0; 3554 int px = 0, py = 0, i;
3527 Ecore_X_Window root; 3555 Ecore_X_Window root;
3528 Ecore_X_Randr_Output *out = NULL; 3556 Ecore_X_Randr_Output *out = NULL;
3529 Ecore_X_Randr_Crtc crtc; 3557 Ecore_X_Randr_Crtc crtc;
3558 Eina_Bool found = EINA_FALSE;
3530 3559
3531 root = ecore_x_window_root_get(ee->prop.window); 3560 root = ecore_x_window_root_get(ee->prop.window);
3532 out = ecore_x_randr_window_outputs_get(ee->prop.window, &outnum); 3561 out = ecore_x_randr_window_outputs_get(ee->prop.window, &outnum);
@@ -3539,15 +3568,40 @@ norandr:
3539 if (ydpi) *ydpi = scdpi; 3568 if (ydpi) *ydpi = scdpi;
3540 return; 3569 return;
3541 } 3570 }
3542 crtc = ecore_x_randr_output_crtc_get(root, out[0]); 3571 for (i = 0; i < outnum; i++)
3543 if (!crtc) goto norandr; 3572 {
3544 ecore_x_randr_crtc_geometry_get(root, crtc, &px, &py, &w, &h); 3573 Eina_Rectangle winrect, outrect;
3545 if ((w == 0) || (h == 0)) goto norandr; 3574
3546 ecore_x_randr_output_size_mm_get(root, out[0], &xmm, &ymm); 3575 crtc = ecore_x_randr_output_crtc_get(root, out[i]);
3547 if ((xmm == 0) || (ymm == 0)) goto norandr; 3576 if (!crtc) continue;
3548 if (xdpi) *xdpi = (w * 254) / (xmm * 10); // 25.4mm / inch 3577 ecore_x_randr_crtc_geometry_get(root, crtc, &px, &py, &w, &h);
3549 if (ydpi) *ydpi = (h * 254) / (ymm * 10); // 25.4mm / inch 3578 if ((w == 0) || (h == 0)) continue;
3579 ecore_x_randr_output_size_mm_get(root, out[i], &xmm, &ymm);
3580 if ((xmm == 0) || (ymm == 0)) continue;
3581 if ((i == 0) || (ecore_x_randr_primary_output_get(root) == out[i]))
3582 {
3583 found = EINA_TRUE;
3584 if (xdpi) *xdpi = (w * 254) / (xmm * 10); // 25.4mm / inch
3585 if (ydpi) *ydpi = (h * 254) / (ymm * 10); // 25.4mm / inch
3586 }
3587 winrect.x = ee->x + (ee->w / 2);
3588 winrect.y = ee->y + (ee->h / 2);
3589 winrect.w = 1;
3590 winrect.h = 1;
3591 outrect.x = px;
3592 outrect.y = py;
3593 outrect.w = w;
3594 outrect.h = h;
3595 if (eina_rectangles_intersect(&outrect, &winrect))
3596 {
3597 if (xdpi) *xdpi = (w * 254) / (xmm * 10); // 25.4mm / inch
3598 if (ydpi) *ydpi = (h * 254) / (ymm * 10); // 25.4mm / inch
3599 free(out);
3600 return;
3601 }
3602 }
3550 free(out); 3603 free(out);
3604 if (!found) goto norandr;
3551} 3605}
3552 3606
3553static void 3607static void